MG3: controller beans scope

1 view
Skip to first unread message

Chris Blackwell

unread,
Jul 24, 2008, 4:41:08 AM7/24/08
to model...@googlegroups.com
I've just run into a situation thats had me scratching my head for a while. I usually arrange my controllers so they all extend a BaseController.cfc in which i setup services used by all my controllers, like SecuritySerivce.  Normally i'd set all these up in BaseController.init()  So with the advent of the beans scope in MG3 i thought i'll stick my security service in the beans scope to keep everything organised, but it appears that the MG3 bean injector destroys the beans scope in the controller before injecting beans required by the subclasses.  Although ModelGlue.gesture.externaladapters.beaninjection.ColdSpringBeanInjector would suggest otherwise =(

heres my simplified code..

<cfcomponent displayname="BaseController" output="false" extends="ModelGlue.gesture.controller.Controller">

    <cffunction name="init" access="public" output="false" hint="Constructor">
        <cfargument name="framework" />
        <cfset super.init(framework) />
<!--- beans struct doesn't exists yet --->
        <cfset variables.beans = structnew() />
        <cfset variables.beans.SecurityService = getModelGlue().getBean("SecurityService") />
        <cfreturn this />
    </cffunction>

    <cffunction name="test">
<!--- a later call to this function will show that beans now contains the beans defined in the subclass metadata, but not SecurityService ?? --->
        <cfdump var="#variables.beans#"><cfabort>
    </cffunction>

</cfcomponent>

Am i doing something dumb here, or is this just not possible??
Cheers, Chris

Joe Rinehart

unread,
Jul 29, 2008, 9:35:08 AM7/29/08
to model...@googlegroups.com
That's really odd, Chris. Since you've dived into it, would you mind
doing some debugging inside of ColdSpringBeanInjector to see if/when
the contents of variables.beans in your BaseController get changed and
SecurityService is wiped, posting any results requiring fixes to http://bugs.model-glue.com/jira?

(Sorry to put two bugs back in your lap! I'll be looking at the
results one, but I can't see anything wrong with bean injection on the
surface of the injector [I've got it open in Eclipse now]).

Thanks,

Joe

Reply all
Reply to author
Forward
0 new messages