I am trying to use my service layer in my own front-controller style framework and I've always been taught to decouple the service layer from the controller layer.
This is causing me issues as I need to access important front-controller methods from my services, so I'm jumping through hoops to try and make this happen.
I noticed when looking at Coldbox however that the actual framework regularly passes the Coldbox controller through to its services.
Can and should this really be done?
The problem I have specifically that my controller/handler calls a service which gets a load of widgets for a page request, it then loops over each one and renders each widget, but each widget is itself a controller/handler and the controller/handler needs the front-controller.
How can this be done without passing in the front-controller or is my architecture all wrong?
CURRENT SERVICE CODE (shortened)
<cffunction name="renderWidgets" access="public" output="false" returntype="string" hint="I return an the prequested webpage URL.">
<cfargument name="source" type="string" default="" />
<cfargument name="templateId" type="string" default="" />
<cfargument name="webPageId" type="string" default="" />
<!--- set original template HTML --->
<cfset stuReturn.renderedHTML = arguments.source />
<!--- get assigned widgets and properties --->
<cfset stuReturn.qryTemplateObjects = findTemplateObjectAssignments({templateId=arguments.templateID}) />
<!--- if found --->
<cfif stuReturn.qryTemplateObjects.recordcount>
<!--- loop over assigned widgets --->
<cfloop query="stuReturn.qryTemplateObjects">
<!--- create struct --->
<cfset stuReturn.stuTemplateObjectAssignment = queryrowtostruct(stuReturn.qryTemplateObjects, stuReturn.qryTemplateObjects.currentrow) />
<!--- get the widget object --->
<cfset stuReturn.renderedHTML = stuReturn.renderedHTML & getFrontController().getWidget(stuReturn.stuTemplateObjectAssignment.objectId).render() /><!--- this is the problem, no access to getFrontController() --->
</cfloop>
</cfif>
<!--- return rendered HTML --->
<cfreturn stuReturn.renderedHTML />