A few wirebox questions

So I have wirebox setup in the config for my app

ioc = { framework = “wirebox”, definitionFile = “config/WireBox” };

and here is my wirebox config

component extends=“coldbox.system.ioc.config.Binder” { public void function configure(){ wireBox = { // Scope registration, automatically register a wirebox injector instance on any CF scope // By default it registeres itself on application scope scopeRegistration = { enabled = true, scope = “application”, // server, cluster, session, application key = “wireBox” }, // DSL Namespace registrations customDSL = { // namespace = “mapping name” }, // Custom Storage Scopes customScopes = { // annotationName = “mapping name” }, // Package scan locations scanLocations = [‘coldboxcatalog.model’], // Stop Recursions stopRecursions = [], // Parent Injector to assign to the configured injector, this must be an object reference parentInjector = “”, // Register all event listeners here, they are created in the specified order listeners = [ // { class="", name="", properties={} } ] }; } }

1st question is i have a coldboxcatalog.model scan location and my securityService is never found. This is because it is in /mode/security/SecurityService. If I change the scan location to coldboxcatalog.model.security it works just fine. Doesn’t this do recursion to search for components?

2nd question is - If I do map a service like above or event like this
map(“SecurityService”).to(“model.security.SecurityService”);

Why do I have to add inject on the property?
property name=“securityService” inject;

Shouldn’t this just be able to wire by name?

finally now that I am configuring wirebox to manage all of my objects/dependencies I can turn of autowiring interceptor right? This should all be handled by wirebox now…

#1 - I looked and the binder does recurse the mapping path to look for
components, so I'm not exactly sure what the problem is. The code is
in system/ioc/config/Binder.cfc @ line 245 if you want to take a
closer look.

on #2, I suspect that you have to explicitly declare injection as both
a performance optimization and a concern that it might inadvertently
inject dependencies that were not intended. I don't mind having to
add inject to my properties, it reads better too. But maybe there
could be a setting added to turn on/of explicitInjection.

.brett

#1 Why would there be an option to not recurse certain directories then? I think recursing the directories would make more sense, can I file an ER any where? haha :wink:

#2 makes sense

Thanks Brett!

Few things for you and this is mostly because I have not published the entire docs yet :slight_smile:

ioc = { framework = “wirebox”, definitionFile = “config/WireBox” };

That declaration is correct. However, this was enabled in order to allow a legacy application built on lightwire or coldpsring to migrate to wirebox without changing the “ioc” injection annotations. If you are starting a fresh new app, you do not need this as WireBox will be created for you automatically by using:

wirebox = { enabled = true };

That will look for your configuration binder by convention in “config/WireBox.cfc”. Or you can specify it explicitly:

wirebox = {
enabled=true,
binder = “config/WireBox”,
singletonReload = true
};

Notice the last setting, singletonReload. This will enable you to reload the singleton scope on each request in the ColdBox app for development purposes, cool!

I added this to the docs already. The scan locations does not mean that it will map all your components in it. It just means that you are giving the factory tentacle pointers to look for objects when you request them. It scans each directory in ORDER to find the requested object. It won’t find your SecurityService with just SecurityService because the scan location path is “security.SecurityService”.

However, if you want to map an entire directory so they are all registered with their named CFC alias, then just do this: mapDirectory(“coldboxcatalog”). This instantiation path will be expanded and all the CFCs in that directory (recursively) will be mapped according to their CFC file name or any “@alias” annotations found on the components.

2nd question is - If I do map a service like above or event like this
map(“SecurityService”).to(“model.security.SecurityService”);

Why do I have to add inject on the property?
property name=“securityService” inject;

No. Because remember that cfproperty is used not only for DI but for ORM, webservices, etc. You need to annotate it in order for WireBox to distinguish it. Not only that, it is great for documentation purposes as your property is now marked for injection.

If you want to NOT add the inject annotaiton you can, but you will have to map it in that target CFC. example:

map(“SecurityService”).to(“model.security.SecurityService”);

map(“Target”).to(“model.myTarget”).property(name=“securityService”, ref=“SecurityService”).noAutowire();

If you use the explicit “property” declaration, then you are declaring all your dependencies EXPLICITLY and do not want autowire anymore (well, you can leave it if you like also). My recommendation is that you choose your style: 1) by annotations, 2) by configuration.

finally now that I am configuring wirebox to manage all of my objects/dependencies I can turn of autowiring interceptor right? This should all be handled by wirebox now…

The autowire interceptor is needed to wire in dependencies to handlers, plugins, interceptors and ORM entities through WireBox.

In the next release WireBox will be the central factory building handlers, plugins and interceptors. However, as of now, these objects need the autowire interceptor to be wired. Please note that this does not apply for model objects or anything that WireBox creates. This is only for handlers, plugins and interceptors to have wirebox wiring capabilities.

.
Luis F. Majano
President
Ortus Solutions, Corp

ColdBox Platform: http://www.coldbox.org
Linked In: http://www.linkedin.com/pub/3/731/483
Blog: http://www.luismajano.com
IECFUG Manager: http://www.iecfug.com

Perfect, thanks for clearing all of that up for me!

the ioc configuration was working for me, I just changed it to the wirebox config above and I am getting the following error. Any ideas why/

Because you are relyin on the IOC and not the model validator

I totally missed the security interceptor!!

{class=“coldbox.system.interceptors.security”,
properties={
rulesSource=“xml”,
rulesFile="/config/securityRules.xml.cfm",
debugMode=“true”,
preEventSecurity=“true”,
validatorIOC=“securityService”
}
}

Just in case anyone else has this issue you will need change that last setting to

validatorModel=“securityService”