I’m trying to upgrade to Coldbox 4 but have no idea how to extend Coldbox models which used to be plugins.
We have extended the plugins ApplicationStorage, HTMLHelper, i18n, QueryHelper, Renderer, ResourceBundle, SessionStorage and Utilities. Some of those are now in modules in Coldbox (which I installed) or even in other places (like Renderer). Could you please tell me, what I have to do to extend these!
No need to extend the plugin CFCs, Just place them inside the Models folders. They can be figure in wirebox config or you can directly get the instance with getModel(“NameOfCfc”)
Thanks for the answer. I’ve already checked out the links you sent me, but thanks anyway. But there’s no answer to my question there.
Maybe I have to explain what I have done and what exactly I would like to achieve, because I just don’t get it to work.
I installed the Coldbox modules (i.e. cbi18n) inside the Coldbox installation on the server. In the Coldbox installation I would like the original Code, so I can replace it in case of new versions without having to check for my modifications.
For our project I would like to handle the getResourceBundle function inside ResourceService differently. So I made a module cbi18n inside our project. In this module I put ModuleConfig which extends the ModuleConfig in Coldbox and overwrites the wirebox bindings for resourceService@cbi18n to take the ResourceService out of my project, not out of the Coldbox module. Also all the places in the Coldbox installation that use ResourceService should take my ResourceService and not the one out of the Coldbox installation.The trouble is that the cbi18n-ModuleConfig from my project doesn’t get executed, instead the module from the Coldbox installation is always used. Also when I look at the loaded modules, the cbi18n module from Coldbox is used, instead of the one out of my project.
So I thought that this might be the wrong approach.
Do I have to put the whole module (cbi18n) only inside my project and change the models in there? But I wouldn’t like that very much. That would mean that in case of a new version of the module I would have to exchange the modules in each project and I would have to check for changes I made and put them into the new version. Is there some other way?
Tonja, If two modules have the same name, ColdBox only loads the first one it finds. If you create a module with a different name, you’d also want to set in it’s ModuleConfig.cfc
this.dependencies = [ ‘cbi18n’ ];
to ensure it gets loaded after the original module.
One thing you might run into is part of the application getting wirebox injections to the original service before your module loads and overrides the WireBox mapping. Another approach you could look into would be a postModuleLoad interceptor. Check for the cbi18n module (or whatever module you want to override) and then override the wirebox mappings right then.
That’s just one part of my upgrade / extend problem. I would also like to extend HTMLHelper and Renderer and these are both not in some module. How do I do that?
Unfortunately now I have a new problem. I can’t inject HTMLHelper as I was used to. I have to use getInstance during runtime, because if I inject it with a property, it will contain the Coldbox-HTMLHelper not mine. The problem is, that I don’t know where to make the mapping, so it’s available at the point where the injections i.e. into module models are made. I can’t extend LoaderService, where the Coldbox mapping for HTMLHelper is made. My mapping AfterConfigurationLoad comes too late. Do you have a suggestion?
Hi Tanja, there is no good solution to this since it turns into a chicken and egg issue. If you don’t want to use getInstance() then the next best thing would be to use a provider:
This will defer the resolution of the mapping ID until you use it the first time. (Basically using getInstance() in the background).
You could try moving your new HTMLHelper mapping sooner in the reinit lifecycle to your /config/WireBox.cfc binder but that won’t work if you are also trying to inject things from your modules into your new version of the helper which is my I originally suggested AfterConfigurationLoad.
I map it in an interceptor afterConfigurationLoad, because when I did the mapping in Wirebox config it didn’t work. I always got the Coldbox version of HTMLHelper instead of my version, even when using getInstance during runtime. But I guess now it works, I just have to inject the provider or use getInstance during runtime and not inject it.