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