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! 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 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