that is very helpful. I had downloaded the Unity code and was working through it, but there is a lot to get your head round in there.
Your sample works perfectly, with one exception. We make a lot of use of Child containers (sometimes three levels deep), and my original Unity 1.2 extension let you fall through to the parent container rather than having each child container cache a new
instance. Here's my two failing unit tests to show what I am trying to achieve:
public void SameCreatedFromTwoChildContainers()
var child1 = container.CreateChildContainer();
var one1 = child1.Resolve<IOne>();
var child2 = container.CreateChildContainer();
var one2 = child2.Resolve<IOne>();
public void WhenCreatedInChildUsesBaseCache()
var child = container.CreateChildContainer();
var one = child.Resolve<IOne>();
var oneBase = container.Resolve<IOne>();
I tried to see if I could exclude my custom build strategy from child containers, but in the Context.ChildContainerCreated I couldn't see a way to remove a strategy from the e.ChildContext.Strategies collection. (you can clear and re-add them all, but you
need to know what build stage each one belongs to).
Alternatively, my strategy could try to find its way to the root container's IBuilderContext and set the persistent policy there, but I haven't found a way to get to the parent IBuilderContext yet
Anyway, sorry to keep pestering you, but any pointers in the right direction would be appreciated.