Kind of a OB2 question... but it is inside an extension to Unity, so maybe I'm following the wrong approach, j
I want to write an extension to unity that registers a mapping when a mapping was requested for an interface, and it doesn't exist.
UnityContainer container = new UnityContainer();
IMyCalculator calculator = container.Resolve<IMyCalculator>();
which would resolve to MyDummyCalculator, by somehow inspecting my types. (particular requisite which is not important for this discussion... :))
i thought on doing this in the OB2 pipeline, with a strategy running on the TypeMapping stage (2nd stage), as this:
public override void PreBuildUp(IBuilderContext context)
IBuildKey originalBuildKey =
context.OriginalBuildKey as IBuildKey;
//1) - Registering the policy for future calls
IBuildKeyMappingPolicy policy = context.Policies.Get<IBuildKeyMappingPolicy>(originalBuildKey);
if (policy == null && originalBuildKey.Type.IsInterface)
Type myDestinationType = null; // obtain the type somehow and validate it
//2) - Registering the policy for future calls
//3) - Registering the mapping for this call
context.BuildKey = originalBuildKey.ReplaceType(defaultMapping.ToType);
My problem is that step 2) does not persist the policy on the policy list. I want my next resolve on the container to have a policy on step 1), and bypass steps 2 and 3.
Any thoughts? Wrong approach? Can't the policies list be changed on the strategy pipeline? Wrong stage?