But if it's working for you, I'm just curious on an academic level
regarding the 'how'.
It might *appear* to work on your dev box if you have model caching
turned off since your singletons are re-created (and re-wired) on every
page request. Production, of course, would have model caching turned
on.
You’re right, I wasn’t taking into account production settings, just development. What Brad was saying is that User.cfc is cached, not because of a setting in User.cfc, but b/c UserService.cfc is cached as a singleton, thus, User.cfc is loaded into UserService.cfc’s instance scope, via autowire, when it’s created.
BeanFactory seems the way to go here for creating new objects.
I apologize for any confusion I may have caused.
Now, this brings up a question I have - How does it work when Even Handler caching is turned on?
What is the advantage of using the BeanFactory over using CreateObject
for transients?
I use CB's DI framework to do model integration. In my Service layer,
I inject my DAO and Gateway and any other singletons I need, but I
don't inject the beans themselves and use CreateObject for the beans
instead. So if I had a UserService, I'd have something like this:
<cfset var User = createUser(argumentCollection=arguments) />
<cfset instance.UserDAO.read(User) />
<cfreturn User />
</cffunction>
</cfcomponent>
Since I'm using CreateObject and my bean doesn't have any caching on
it, it should create a new transient every time. Thus far my approach
seems to work. What, then, do you think the advantage of using the
BeanFactory would be?
Some benefits for me have been that I can inject the transient using
an alias. That ensures it will still work when I have had to change
the locations of the physical files.
Additionally, I can still use coldbox model integration in transients
whereas createobject would break that.