RE: [coldbox:3212] Re: Auto Wiring Transients in Service Layer

I don't know if I followed the entire conversation, but I want to
clarify something. If by "your method" you mean you mean using the
cfproperty tag in notify the autowire interceptor that an instance of
the model specified needs to be injected into the CFC, then that would
NOT work if your goal was to have access to unlimited *new* User
objects.

Take the following CFC for instance:

<cfcomponent output="false" autowire="true">
    <cfproperty name="User" type="model" scope="instance" />

     <cffunction name="newUser">
       <cfreturn instance.User>
    </cffunction>
</cfcomponent>

Let's assume the CFC above is a singleton called UserService which is
created and initialized _once_ and stored in the ColdBox cache. Calling
the "newUser" method would always return the same User bean even if
"cache" was set to "false" in the user.cfc. This is because the
cfproperty autowiring is executed only once when the UserService is
created and a reference to the same User bean that is set into the
instance scope (which lives for the life of the object in the
"variables" scope) will be handed out over and over again.

If you have a singleton (like UserService) that you want to be able to
create new copies of transients (like User beans) via an object factory
(which is necessary for the transient to be wired itself properly) then
you have to wire the beanFactory plugin into the singleton and call
getModel every time you want a new copy of your transient.

~Brad

Brad,

Thank you very for the explanation as it clarifies my understanding. I
use the beanfactory for transients or 'getModel' if I'm in a handler
but I try to keep an open mind as I'm still learning.

Dutch,

Now I'm even more curious about your method and if it's indeed working
for you. To test, I usually open the same page in a different browser
and, if you inject by cfproperty, the object will already exist and
have the same instance data. Hence, it's not working as a transient.

But if it's working for you, I'm just curious on an academic level
regarding the 'how'. :slight_smile:

- Gabriel