[wirebox-1.8.0] missing else in ioc.Builder?

I believe I’ve come across a problem in the mentioned component while implementing a custom DSL namespace.

Disclaimer: its late and I haven’t thoroughly searched the docs/forums, so I don’t know if 1) its expected behavior or 2) there’s a better way. With that, I proceed:

First let me give some background and explain what I’m going for. I’m wanting to use wirebox more similarly to Google Guice, where you map an interface class to an implementation class:

`
// within the Paypal Module
bind(PaymentProcessor.class).to(PaypalProcessor.class);

// within the Credit Card Module
bind(PaymentProcessor.class).to(CreditCardProcessor.class);

class Payment {
@Inject
public void Payment(PaymentProcessor processor) {
// when created by the paypal module, processor is an instance of the PaypalProcessor,
// likewise, when created by the credit card module, it is an instance of CreditCardProcessor…
}
}
`

Back to the coldfusion side…I have a package of interfaces with subpackages of implementations:
/app/pkg/SomeObject.cfc // <- interface
/app/pkg/adb/SomeObject.cfc // <- component implementing the above interface.
/app/pkg/odb/SomeObject.cfc // <- component implementing the above interface.

I wanted to rely on the type field of properties in my dependent CFCs:

`
// mappings…
map(“app.pkg.SomeObject”).to(“app.pkg.adb.SomeObject”);

component {
/**

  • @inject
    */
    property app.pkg.SomeObject object; //fails - cannot resolve…
    }
    `

Apparently, you either have to map the dependency using the property name, or specify the type in both the inject AND the type. Either too redundant, or too tedious to try to remember all the types and what they are registered in the injector as… I want to rely on what is already available in CFML (specifically Railo) as much as possible. I caught a glimpse on the google forums explaining that you didn’t want to “hack the type” value anymore, which is understandable, but for my use case, unusable.

Therefore… getting close to the bug, I promise! :slight_smile: I defined a custom dsl namespace that I called bytype. Use case:

`
/**

  • @inject bytype
    */
    property app.bean.SomeObject object;
    `

I can dump and abort from within my namespace object during resolution and it works exactly how I want - the only problem is that it keeps throwing an exception after exiting my namespace object even though I’ve already confirmed my namespace resolved correctly.

Therefore, and this is the bug: I believe there is a missing else statement around line 350 of wirebox.system.ioc.Builder;

`

// Check if Custom DSL exists, if it does, execute it
if( structKeyExists( instance.customDSL, DSLNamespace ) ){
refLocal.dependency = instance.customDSL[ DSLNamespace ].process(argumentCollection=arguments);
}

/* missing else??? */

// If no custom DSL’s found, let’s try to use the name as the empty namespace
if( NOT find( “:”, arguments.definition.dsl ) ){
arguments.definition.dsl = “id:#arguments.definition.dsl#”;
refLocal.dependency = getModelDSL(argumentCollection=arguments);
}

`

I tested my change locally, and it seems to work beautifully :slight_smile: Other than that I’m impressed with how well it works so far.

If there is a better way to do what I want, I’m open to suggestions. You might also could take this as a feature request to bake in the bytype namespace, either that or add an annotation @injectByType

I really like the approach you are doing as it makes folks with a java background more approachable to cf.

I was inspired by guice when designing wirebox.

Can you create a ticket for this in jira please?

Also I kinda like where you created a namespace for it. I say contribute it and we will add it to the core.

Will do - I did have to make some changes in other places, and I’m not sure I got everything… Basically, I had to modify the builder to make it copy the type annotation into the DI definition as supplied to the DSL parser (what I previously thought was working great, wasn’t really working at all).

Other than that, I’ll certainly contribute the bytype DSL.

Added issue COLDBOX-306, with a patch attached to the issue.

Jesse, is there a way ou can send a pull request?

Luis F. Majano
CEO
Ortus Solutions, Corp
www.ortussolutions.com

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

Social: twitter.com/lmajano facebook.com/lmajano