[ColdBox-4.1.0] Mapping to module's model objects in Wirebox

143 views
Skip to first unread message

Nick

unread,
Sep 14, 2016, 10:34:09 PM9/14/16
to ColdBox Platform
At the moment I can map to a model object in my module by doing this:

map("myService").to("modules.myModule.models.services.myService").asSingleton();

Is it possible to shorten it to:

map("myService").to("myModule.models.services.myService").asSingleton();

I tried setting in ModuleConfig.cfc
this.cfmapping = "myModule";

but didn't work.


Sana Ullah

unread,
Sep 15, 2016, 12:15:01 PM9/15/16
to col...@googlegroups.com
Hi Nick,

You can map models of module like this 

map("myService").to("#moduleMapping#.models.services.myService").asSingleton();


following information for module config

/**
Module Directives as public properties
this.title = "Title of the module";
this.author = "Author of the module";
this.webURL = "Web URL for docs purposes";
this.description = "Module description";
this.version = "Module Version";
this.viewParentLookup   = (true) [boolean] (Optional) // If true, checks for views in the parent first, then it the module.If false, then modules first, then parent.
this.layoutParentLookup = (true) [boolean] (Optional) // If true, checks for layouts in the parent first, then it the module.If false, then modules first, then parent.
this.entryPoint   = "" (Optional) // If set, this is the default event (ex:forgebox:manager.index) or default route (/forgebox) the framework
      will use to create an entry link to the module. Similar to a default event.
// Execution Aliases
this.aliases = [];
// Auto Map Models Directory
this.autoMapModels = true;
// Model Namespace
this.modelNamespace = "";
// CF Mapping
this.cfmapping = "";
// Module Dependencies
this.dependencies = [];

structures to create for configuration
- parentSettings : struct (will append and override parent)
- settings : struct
- datasources : struct (will append and override parent)
- interceptorSettings : struct of the following keys ATM
- customInterceptionPoints : string list of custom interception points
- interceptors : array
- layoutSettings : struct (will allow to define a defaultLayout for the module)
- routes : array Allowed keys are same as the addRoute() method of the SES interceptor.
- wirebox : The wirebox DSL to load and use

Available objects in variable scope
- controller
- appMapping (application mapping)
- moduleMapping (include,cf path)
- modulePath (absolute path)
- log (A pre-configured logBox logger object for this object)
- binder (The wirebox configuration binder)
- wirebox (The wirebox injector)

Configuration Method
- configure() : The method ColdBox calls to configure the module upon framework initialization

Life Cycle Methods
- onLoad() : If found, it is fired once the module is fully loaded
- onUnload() : If found, it is fired once the module is unloaded

*/


Warm Regards
Sana

--
--
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/6dd92fc8-36a3-4fc9-bf10-af1d806bb9f4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Brad Wood

unread,
Sep 15, 2016, 2:43:57 PM9/15/16
to ColdBox Platform
What Sana suggested is the proper way to get the full path.  This is very important since you can't control where the module might be installed to (it might not even be in the web root).

However, what is much better is simply to add the singleton annotation to your CFC and then there is no need to map it at all!  ColdBox will automatically map all models recursively in your models folder as long as autoMapModels is enabled in your ModuleConfig.cfc (default for ColdBox 4.+)

component singletion {
}

Thanks!

~Brad

Nick

unread,
Sep 16, 2016, 7:37:49 AM9/16/16
to ColdBox Platform
Thanks Sana and Brad, will give both approach a go.
Reply all
Reply to author
Forward
0 new messages