RE: [coldbox:15664] mapDSL("entityService") - trying to get funky

Sean, I’ve never used a custom WireBox DSL namespace, so I can’t answer authoritatively but after perusing the code, I don’t see how you would be able to override an existing namespace.

In coldbox/system/ioc/builder.cfc in the buildDSLDependency() method, all the “normal” namespaces are checked first (like entityServiceand) and delegated to other methods (like getEntityServiceDSL
()).

It isn’t until the list of normal namespaces has been exhausted, that the customDSL is checked which is where your custom builder kicks in.

If I were to guess, I’d say that the docs are wrong. It would be possible to change WireBox and allow the custom DSLs to override the internal ones by reversing the order of the lookups, but I’d like to hear Luis weigh in.

In the meantime, you may be able to create an intermediate mapping ID in your config which points to either the entityService or your own builder and then autowire that ID into your components. I don’t think that will allow you to do two-stage DSLs though like inject=“entityService:person”. You could just map(“myEntityService”).toDSL(“entityService OR mongoEntityService”) and then autowire inject=“myEntityService” but NOT inject=“myEntityServiceL:person”

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

Thanks Brad, that’s good info. I’d be curious to hear Luis weigh in on this too. In the meantime, I’ve thought of another possible approach, which is to use a custom DSL with a different namespace, like “mongoEntityService:myEntity”, and use a CB setting to determine what to inject. Something like:

Of course this would not work in model objects unless I injected coldbox:setting as well. I guess I would have to use setter injection in those cases. Hm.

Another thought, is it possible to map a custom namespace to an internal one? So for example, I create “myEntityService” namespace, and in apps where I want to use the normal entityService I just map “myEntityService” to “entityService”, and in apps where I want to use my custom one, I map to that instead. Then in my shared modules I just always inject using “myEntityService”.