Auto Wiring Transients in Service Layer


Is is possible to use ColdBox as a Transient Factory?

I looked at the example on the cbModelGuid wiki page [http://] and it is
creating the User with a CreateObject function.

I know that I could use the IoC plugin and Lightwire as a Transient
Factory, but can you use the GetModel("User") to do something like:

<cfcomponent name="UserService" output="false" cache="true"

  <!--- Dependencies --->
  <cfproperty name="SessionStorage"
type="coldbox:plugin:sessionstorage" scope="instance" />
  <cfproperty name="HandlerService" type="coldbox:handlerService"
scope="instance" />

  instance = structnew();

  <cffunction name="init" output="false" returntype="UserService">
    <cfreturn this>

  <cffunction name="getUserSession" output="false" access="public"
                        hint="This method checks if a user is in an
authorized session, else it returns the default user object.">
                var oUser = "";

                //Is user in session
                if ( instance.sessionstorage.exists( 'CurrentUser' ) )
                        oUser = instance.sessionstorage.getVar
( 'CurrentUser' );
                        oUser = instance.HandlerService.GetModel

                /* Return User Object */
                return oUser;



I think I've answered my own question. You can do it by injecting the
BeanFactory plugin.

<cfproperty name="BeanFactory" type="coldbox:plugin:BeanFactory"
scope="instance" />



As long as you don’t specify the cache=“true” meta data in your model objects, a transient will always be created.

Let’s say I have a User.cfc:

And in my handler, I want to get it:

In this case, rc.user1 and rc.user2 both represent different objects. (When you dump them, rc.user2 will have empty properties)

But, it if I add cache=“true” to my User.cfc:

User.cfc then becomes a singleton and rc.user1 and rc.user2 reference the same object.

Looking at your code, you probably don’t need to wire the Handler Service, instead, just add

and simply do
oUser = instance.User


Hi John,

<!--- Transient: Used on demand --->
<cfcomponent name="UserGroup">

The coldbox provide three different scopes for DSL "instance,
variables, this"



I use the beanfactory to handle transients because I experience the
opposite if I use your method. If I use your method with production
settings, the object is cached even though I have 'cache="false"' in

Again, I use the beanfactory so I'm not currently experiencing a
problem but if your method is working for you with production
settings, I'll have to look into why it doesn't work with my settings.

- Gabriel