Nested Containers in Unity

Apr 29, 2009 at 3:17 PM
What limitations are there when leveraging nested containers?  I have a reference application that tries to apply the same PIAB policy to a parent and child container. Each container has its own group of policies that are associated with it.  What I found was that the same Policy Name cannot be used for both containers.  If a policy called "Caching Policy" exists for both, it will not be applied to the child container after it has been applied to the parent container.

Another situation we've come across is in using the same concrete type in both a child and parent container.  Is this an invalid action?  So if we have a config below, after code is executed to resolve the type mapping in the Parent Container, subsequent code that tries to access the type from the child container fails.  Is this expected behavior?  It appears that the Transient Lifetime manager is not returning a new instance each time...

Thanks,
Roland

    <unity>
        <typeAliases>
            <typeAlias alias="ILogicService" type="Foo.ILogicService, Foo" />
            <typeAlias alias="LogicService" type="Foo.LogicService, Foo" />
...
        </typeAliases>

        <containers>
            <container name="Parent Container">
                <types>
                    <type type="ILogicService" mapTo="LogicService" />
...
                </types>
  
            </container>
            <container name="Child Container">
                <types>
                    <type type="ILogicService" mapTo="LogicService" />
   ...                
                </types>
            </container>
        </containers>
    </unity>

Apr 30, 2009 at 7:22 AM
What you're describing should just work. Could you give me a working code sample (not just the config, the actual code) that demonstrates the problem so I can debug it?