Hi everybody,
Ran into a small issue. I have a Module called SessionModule.
Inside its configure method I define 3 wirebox bindings:
binder.map(“SessionDAO@DAO”)
.to("#moduleMapping#.model.dao.SessionDAO");
binder.map(“sessionService@services”)
.to("#moduleMapping#.model.services.SessionService")
.asSingleton();
binder.map(“Cookie@Plugins”)
.to("#moduleMapping#.plugins.Cookie");
I also created a SessionModuleFlash component:
/**
* Flash component to handle flash data using our custom session module
*/
component extends=“coldbox.system.web.flash.AbstractFlashScope” singleton{
property name=“sessionService” type=“any”;
any function init(required any controller){
super.init(arguments.controller);
instance.flashKey = “cbox_flash”;
variables.sessionService = controller.getWireBox().getInstance(“sessionService@services”);
return this;
}
public string function getFlashKey(){
return instance.flashKey;
}
public void function saveFlash(){
sessionService.add(instance.flashKey, getScope());
}
public void function clearFlash(){
if(flashExists()){
sessionService.remove(instance.flashKey);
}
}
public struct function getFlash(){
if(flashExists()){
return sessionService.get(instance.flashKey);
}
return {};
}
public boolean function flashExists(){
return sessionService.exists(instance.flashKey);
}
}
In my main application’s coldbox.cfc:
flash = {
scope = “modules.SessionModule.model.flash.SessionModuleFlash”,
properties = {}, // constructor properties for the flash scope implementation
inflateToRC = true, // automatically inflate flash data into the RC scope
inflateToPRC = false, // automatically inflate flash data into the PRC scope
autoPurge = true, // automatically purge flash data for you
autoSave = true // automatically save flash scopes at end of a request and on relocations.
}
This will not work because flash is initialized before any of the ModuleConfigs are loaded. This means that wirebox does not yet know about the plumbing of your modules flash component.
It is easily fixed by moving the bindings into your main apps wirebox.cfc, but this goes against my code-smell where I want my module to encapsulate its plumbing.
Ideally I would want to define or override the flash settings of my main application so that any application using my SessionModule will automatically use it for Flash RAM.
I will have a look at the coldbox bootstrap sequence to see if I can remedy the Issue, but I was just wondering if anyone else ran into this and maybe already has a solution?