Pull Request: WireBox Provider Fixes

Here are the details of a pull request I just submitted and the associated ticket I entered for the changes.

https://github.com/ColdBox/coldbox-platform/pull/99

http://www.assembla.com/spaces/coldbox/tickets/1381-wirebox-provider-fixes–

  • Allow provider objects and provider methods to provide DSLs and not just mapping IDs.
  • Also, pass along targetObject always so logbox:logger:{this} works everywhere.
    This allows for the following things:

In model/handler:

In Binder Config:

map(“myLogBoxID”).toDSL(“logbox:logger:{this}”);
map(“myProvidedLogBoxID”).toDSL(“provider:logbox:logger:{this}”);

In order to allow provider objects and provider methods to provide anything instead of just mappings by ID, I changed providers to pass DSL into getInstance instead of name. This works well, since getInstance defaults to getting by ID if it can’t resolve the DSL.

The DSL logbox:logger:{this} also only worked in some instances-- and providers was one place it didn’t work since they didn’t pass around the targetObject. I modified all the methods related to building DSLs to always pass along targetObject so it is always available, even when building a logbox DSL via a provider. Since I had to add targetObject to IScope.getFromScope(), and IInjector.getInstance() that twill be a compatibility issue with anyone who has implemented a custom scope or injector since the interface changed.
A couple notes on some code that might not be obvious.

The LogBoxDSL builder used to check to see if the instance ID existed and throw an error if not when building the provider. That isn’t really possible when building a provider for a DSL since the DSL won’t be evaluated until the provider is actually invoked. The only choice to to just build the provider, and the injector will throw an error later when the provider is actually used if the DSL can’t be built then.

You’ll notice I defaulted targetObject to an empty string in most methods. I don’t really care for that, but it’s the lesser of three evils. Since it doesn’t always exist and I need to pass it along through several methods when it does exist, the only options are:

  • Have a bunch of if statements with two method calls-- one that passes targetObject when it exists and another that ignores it which would end up with annoying duplicated code
  • Convert all the intermediate calls to use argumentCollection which would take several extra lines of code each time to build up the argument struct.
  • Always pass it along, defaulting to “” along the way, and just check targetObject to see if it an actual object when I’m ready to use it in the logbox DSL builder.
    I chose the third option because it left the code cleaner.

I tried to add unit tests for the major areas I touched as well as tests in InjectorCreationTest for the actual new functionality.

For some reason this pull request shows 52 commits. 51 of those are me just merging upstream/development into my fork so my code is up-to-date. I don’t know how to get rid of those, but the 19 tiles that show as changes are the actual changes that relate to my single commit.

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

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