Instantiate a component object
Hi! I'm not too clear with instantiating a component object and using cfinvoke to call the function.
To make it clear I'm going to use an easy example as follow:
Supposed I have a registration application where all it does was just getting user information, validate them and insert them into a table.
Since this functionality will be used repeatedly by many new users, I made it into a component.
So I will have:
MyComponent.cfc :
<cfcomponent displayname="UserRegistration" output="false">
<CFFUNCTION name="Init" access="public" returntype="any" output="false" hint="Returns an initialized component instance.">
<cfreturn THIS />
</CFFUNCTION>
<CFFUNCTION name="Validate_and_Store_User" hint="Store registration data" >
<cfargument name="st_NewUser" type="Struct" required="True">
There will be user validation and SQL Insert script in here
</CFFUNCTION>
</cfcomponent>
The Calling page is: RegistrationPage.cfm:
I'm calling it this way:
1. Instantiate the component object:
<cfset objRegistration = createObject('component', 'MyComponent') />
then call the UDF:
<CFINVOKE component="#objRegistration#" method="Validate_and_Store_User" st_NewUser ="#st_NewUser#">
My question is:
When a new user is trying to register, first, the component object is instantiated and then the UDF is called
But when there are more new users registering at the same time, does it means the component object got instantiated over and over again instead of just once?
Looking at the code, CF will run <cfset objRegistration = createObject('component', 'MyComponent') /> everytime a user is registering and this mean an instant of that component is created, so every user will instantiate a component object? is this how it is supposed to work?
I'm just using a registration as an example. My core confusion is on whether or not an instant of component need to be created for each user.
Thanks!
