Model Glue does not do DI with the makeEventBean stuff. What you should do
is update your service to pass in the dependencies needed by the bean.

(And you would do well to avoid as many dependencies in your beans, because
from this email exchange you tend to confuse the responsibilities of each)

So this method you wrote:

menuService.getNewMenuBean()

The service is managed by ColdSpring. Thus, you would need the setters in
the MenuService.

Next, in the method getNewMenuBean() (which may need to be renamed, because
you aren't 'getting' a new menu bean, you are making or creating one. This
is purely style points though), you would then do this:

<cfset newBean = createobject("component", "Application.Beans.MenuBean").init()
/>
<cfset newBean.setOneDependency( getOneDependency() ) />
<cfset newBean.setTwoDependency( getTwoDependency() ) />
<cfreturn newBean />


Since you'll only create new MenuBeans from the service, you'll be in good
shape. Bottlenecking bean creation through a factory is a good thing to do
when there are dependencies or when you want to leave all bean paths in the
ColdSpring file, By the way...

DW







On Mon, Sep 26, 2011 at 5:26 PM, marc <[email protected]> wrote:

> Dan,
>
> I changed the original handler in the controller from
>
>
> <cffunction name="get">
>         <cfargument name="event" type="any" required="true">
>         [...]
>         <cfset
> arguments.event.setValue("allMenus",beans.MenuService.list(local.domainId))>
>         <cfset
> arguments.event.setValue("allSameLevelMenus",beans.MenuService.getMenusWithSameParent(domainId=local.domainId,parentMenu=local.menuBean.getParentMenu()))>
>         [...]
>     </cffunction>
>
> to
>
>
> <cffunction name="get">
>         <cfargument name="event" type="any" required="true">
>         [...]
>         <cfset
> arguments.event.setValue("allMenus",beans.MenuService.list(bean=arguments.event.makeEventBean('Application.Beans.MenuBean'),domainId=local.domainId,currentMenuId=local.menuId))>
>         <cfset
> arguments.event.setValue("allSameLevelMenus",beans.MenuService.getMenusWithSameParent(bean=arguments.event.makeEventBean('Application.Beans.MenuBean'),domainId=local.domainId,parentMenu=local.menuBean.getParentMenu(),currentMenuId=local.menuId))>
>   [...]
>     </cffunction>
>
> This gives me 2 separate instances of the menuBean since when I do this
> (essentially the same)
>
> <cfset bean1=arguments.event.makeEventBean('Application.Beans.MenuBean')>
> <cfset bean1.test=CreateUUID()>
> <cfset bean2=arguments.event.makeEventBean('Application.Beans.MenuBean')>
> <cfset bean2.test=CreateUUID()>
> bean1.test=<cfoutput>#bean1.test#<br /></cfoutput>
> bean2.test=<cfoutput>#bean2.test#</cfoutput>
> <cfabort>
>
> I get 2 different values.
>
> In the menuService I call the MenuGateway with the exact same arguments (so
> actually MenuService is an extra layer) and in the menuGateway I populate
> and return the MenuBean:
>
>
>     <cffunction name="list" returntype="Application.Beans.MenuBean"
> hint="">
>         <cfargument name="bean" type="any" required="false"default=""
> hint="bean to populate and return">
>         [...]
>           <cfreturn
> arguments.bean.populateBeanCollection(local.Transfer.listByQuery(local.query))>
>     </cffunction>
>
> BUT when I create a menuBean this way Dependency Injection in the menuBean
> does not work. The Menubean looks like this:
>
> <cfcomponent
>     accessors="true"
>     displayname="MenuBean"
>     extends="Application.Beans.BaseBean"
>     output="false"
>     persistent="true">
>
>     <cfproperty name="ArrayService">
>     <cfproperty name="QueryService">
>
> <cffunction name="populateBeanCollection" hint="assign query resultset to a
> bean property">
>     [...]
>     <cfset Variables.CollectionObject=getQueryService()>
>     <cfset
> Variables.CollectionObject.populateBeanCollection(arguments.object)>
>     [...]
> </cffunction>
>
> In the MenuBean I rely on DI via accessors (<cfcomponent accessors="true">
> and <cfproperty name="QueryService">) but the call to getQueryService()
> gives a value of undefined, where it should give me an instance of the
> QueryService (same with ArrayService btw)
>
> Calling getQueryService() _used_ to return a valid object before, when I
> didn't create the bean via makeEventBean in the controller.
>
> Looks like MG does not do DI when calling a bean via MakeEventBean in the
> controller. Is this because I do not manage my controllers with Coldspring?
> Should that solve this problem? And if so, how do I turn that on?
>
>
> Marc
>
> --
> Model-Glue Sites:
> Home Page: http://www.model-glue.com
> Documentation: http://docs.model-glue.com
> Bug Tracker: http://bugs.model-glue.com
> Blog: http://www.model-glue.com/blog
>
> You received this message because you are subscribed to the Google
> Groups "model-glue" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/model-glue?hl=en
>



-- 
Plutarch - "The mind is not a vessel to be filled but a fire to be kindled."

-- 
Model-Glue Sites:
Home Page: http://www.model-glue.com
Documentation: http://docs.model-glue.com
Bug Tracker: http://bugs.model-glue.com
Blog: http://www.model-glue.com/blog

You received this message because you are subscribed to the Google
Groups "model-glue" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/model-glue?hl=en

Reply via email to