As far as I know child containers are thread safe. Another approach would be to use a per request lifetime manager similar to what is in
Unity bootstrapper for ASP.NET MVC
If you are resolving one object (e.g. a WCF service) and constructing the object graph for that one object per request then you might be able to just use a
to specify an IAuthenticateduser instance to use wherever there is a dependency of the type IAuthenticateduser for the entire object graph. See
Using Dependency Overrides
for some examples.
Enterprise Library support engineer
Thanks for the answer.
I can not use dependency overrides, because I am resolving multiple times. I've been explicitly registering IUnityContainer so that clients could resolve agaisnt it. However this caused StackOverflow exception on Dispose (). Googling for it I have found, that
this is a well known problem. When I removed explicit registration, everything worked OK. You might want to consider throwing exception as part of Registration to avoid crasing Dipose.,
I've taken a look at Uniy.Mvc5, (https://github.com/feedbackhound/Unity.Mvc5/blob/master/Unity.Mvc5/UnityDependencyResolver.cs
) and I
can see that it is also using CreateChildContainer.
I also examine the source code of UnityContainer and its uses locks when modifying list of child containers.
So child containers are the way to go!.