[Coldbox-3.5] Modules Model configuration

38 views
Skip to first unread message

JD

unread,
Mar 14, 2018, 10:44:26 AM3/14/18
to ColdBox Platform
I'm looking to create a module that will look for handlers/models/views inside the module first and then the parent if they don't exist. I have the handlers part working but can't seem to get the models to look in the module first.

Here is my ModuleConfig:
// Module Properties
this.title = "myModule";
this.version = "1.0";
this.entryPoint = 'myModule';
// If true, looks for views in the parent first, if not found, then in the module. Else vice-versa
this.viewParentLookup = false;

// If true, looks for layouts in the parent first, if not found, then in module. Else vice-versa
this.layoutParentLookup = false;

this.autoMapModels = true;

this.parseParentSettings = true;

this.modelNamespace = "myModule";


function configure() {
    interceptorSettings = {
customInterceptionPoints = ""
    };
    conventions = {
handlersLocation  = "handlers",
viewsLocation     = "views",
modelsLocation    = "model"
    };
  
    binder.mapDirectory("#moduleMapping#.model");
}


In the handler in my module I have a property set:
<cfcomponent>
    <cfproperty name="myService" inject="model:service.myService" scope="instance">
    <cffunction name="myFunction">
        <cfset var temp=instance.myService.myServiceFunction()>
    </cffunction>

And that is calling the model/service/myservice.cfc in parent and not the one I created in module/myModule/model/service/myService.cfc.

What am I doing wrong.

Ancient Programmer

unread,
Mar 15, 2018, 12:47:04 PM3/15/18
to ColdBox Platform
For the view, follow the directory structure described in this page:


For the model, in ModuleConfig.cfc, add this:

// Binder Mappings
// binder.map("Alias").to("#moduleMapping#.model.MyService");
binder.map("MyService").to("#moduleMapping#.model.MyService");


I hope that helps,

Brad Wood

unread,
Mar 16, 2018, 12:15:39 AM3/16/18
to col...@googlegroups.com
You can't have automatic overrides of models.  WireBox mapping IDs are unique and the last/first one (I think you can choose) to be registered will be used.  You can build this behavior though if you want.  Manually create a new WireBox instance in your module's onload and set the "parentInjector" to be the core wirebox instance.  Then, instead of using any injection DSL, pass in your custom WireBox injector and if it doesn't have the model registered, it will ask the parent injector for it.  Just like class loaders in Java.  Just make sure to change the default application scope registration in WireBox so it doesn't overwrite the core one.

Thanks!

~Brad

Developer Advocate
Ortus Solutions, Corp 

ColdBox Platform: http://www.coldbox.org 


--
--
You received this message because you are subscribed to the Google Groups "ColdBox Platform" group.
For News, visit http://blog.coldbox.org
For Documentation, visit http://wiki.coldbox.org
For Bug Reports, visit https://ortussolutions.atlassian.net/browse/COLDBOX
---
You received this message because you are subscribed to the Google Groups "ColdBox Platform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to coldbox+unsubscribe@googlegroups.com.
To post to this group, send email to col...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/coldbox/b182021e-8541-4081-b19e-4e7a48d80bf7%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

JD

unread,
Mar 16, 2018, 10:32:50 AM3/16/18
to ColdBox Platform
Thank you for the help on this. 

Is there a way that I can send in the name of the module into the injection to specify that I want to use the modules model instead of the parent?

I saw this: 

So using my example above, I tried this: 
<cfproperty name="myService" inject="model:service.myService@myModule" scope="instance">
But can't seem to get it to work. I get a Builder.DSLDependencyNotFoundException.
To unsubscribe from this group and stop receiving emails from it, send an email to coldbox+u...@googlegroups.com.

To post to this group, send email to col...@googlegroups.com.

Brad Wood

unread,
Mar 16, 2018, 2:24:44 PM3/16/18
to col...@googlegroups.com
Not out of the box, but you could always write your own injection namespace DSL.  Sound like more work than just swapping your cfproperties with mySpecialWireBox.getInstance().

Thanks!

~Brad

Developer Advocate
Ortus Solutions, Corp 

ColdBox Platform: http://www.coldbox.org 


To unsubscribe from this group and stop receiving emails from it, send an email to coldbox+unsubscribe@googlegroups.com.

To post to this group, send email to col...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages