CreateChildContainer: I need to intercept child container's creation

May 20, 2008 at 6:12 PM
I asked some time ago about CreateChildContainer, why it doesn't copy extensions into child.
If it's imposible or supposed incorrent, then may be you could give some way to intercept child's creation?
Some event firing here:
        public override IUnityContainer CreateChildContainer()
            return new UnityContainer(this);
Then I could copy my extensions into a child.
Please :)

May 20, 2008 at 7:53 PM
Any chance you can use subclassing to achieve what you want? I.e.:

class MyUnityContainer : UnityContainer
  public MyUnityContainer() : base() { }

  public MyUnityContainer(IUnityContainer parent) : base(parent) { }

  public override IUnityContainer CreateChildContainer()
    var result = new MyUnityContainer(this);
    CopyExtensionsTo(result); // however you would do that :)
    return result;

May 21, 2008 at 10:14 AM
no chance,
because in derived class we don't have access to extensions. We even can't enumerate them.
May 21, 2008 at 10:27 AM
one more reason - constructor with "IUnityContainer parent" agrument is private:
private UnityContainer(UnityContainer parent)