InjectionProperty Add vs. Set

Mar 27, 2008 at 2:34 AM
I am working on the PropertyMapping extension that I discussed at the workshop. Right now I'm looking at using InjectionProperty as the method in which to create the properties per mapping type. However, I want to create a temporary set of InjectionProperties and then remove them after they have been built. I see there's a ConfigureInjectionFor() method, but is there a way to remove an InjectionMember after it has been added?
Mar 27, 2008 at 5:47 AM
There is no such method right now. If I added one I think my docs guy would strangle me, so don't expect it in the release.

However, it's actually pretty easy to do in your own extension. The InjectionMember stuff ends up adding ObjectBuilder policies. So all you'd need to do is remove said policies (and any current build plan) and it'd be as if you never added them in the first place.

Take a look through the code in the Injection directory of the source; that'll tell you which policies are being added. IConstructorSelector, IPropertySelector, and IMethodSelector are the relevant ones. Also look at the source code for ConfigureInjectionFor - there's a couple more things that are done in there to get rid of the current build plan (which needs to change if what you're injecting changes).

Hope this helps!
Mar 27, 2008 at 5:48 AM
Oh, another option would be to create a child container, configure your policies in that, then throw it away after the build.
Mar 27, 2008 at 1:06 PM


ctavares wrote:
Oh, another option would be to create a child container, configure your policies in that, then throw it away after the build.



That's awesome. I'll do exactly that. :) Thanks!