Boris Schwarz
05/24/2024, 9:36 AMassetService.cfc
. It would contain getStyles()
, getMetaData()
, getScripts()
and all sort of things.
Now, depending on the area of the application I'm in, these functions should ouput different things, so I created multiple services (frontendAssetService.cfc, backendAssetService.cfc, ect.
) that all implement the same interface IAssetService.cfc
, making those functions required. Whenever there will be a new area in the app, I just have to create a new "sub-service".
Now in my assetService.cfc:init() I was returning an instance of one of those other sub-services, which worked well until I turned off reloadApplicationOnEveryRequest
and realized the service was cached as a singleton and would always return the sub-service that was created on the last app-reload.
"No problem", I thought and switched the assetService.cfc to transient, however I cannot seem to invoke them directly with getAssetService()
in my controller.cfc. I would have to get it via fw.getBeanFactory().getBean('assetService')
.
"Back to singleton", I said and implemented the onMissingMethod()
method, which then invoked the correct sub-service, checks for the function to exist there and returns it.
It seems like a big hack. Does anyone know a better solution for this? I feel like I'm running into the same wall again and again.
Eventuall I would just like to invoke rc.htmlHeadStyles=getAssetService().getStyles()
in my controller.cfc instead of having a very big <cfif><cfelse>
in my layout.cfm.
Any ideas highly welcome!
Cheers, BorisBoris Schwarz
05/24/2024, 9:39 AMgetFrontendAssetService()
in the corresponding subsystems and getBackendAssetService()
in the others(?) 🤦♂️dswitzer
05/24/2024, 11:22 AMgetStylesByService(required string name)
method, that could load the styles for various services, that way you could do:
rc.serviceName = 'frontend'; // this could come from session scope
rc.htmlHeadStyles=getAssetService().getStylesByService(rc.serviceName);
Or you could just set an rc.AssetService
variable at the controller which passes in the correct version of the component.Boris Schwarz
05/24/2024, 11:33 AM