StackOverflow when Disposing a container

Feb 11, 2010 at 1:52 AM

Try this:

          var container = new UnityContainer();

yields a stack overflow.


I register the unity container in itself so I can use it in constructor injection.

assume my class constructor looks like this:

public class MyWorker(IUnityContainer container, ILogger logger)....

I can resolve it like this:

var myWorker = container.Resolve<MyWorker>();

Feb 11, 2010 at 2:51 AM

Ok, I just realized that the unity container will inject itself by default.  which means I shouldn't be registering itself as the instance of IUnityContainer.

Any other types that I shouldn't be registering?


Feb 11, 2010 at 7:05 AM

No, the IUnityContainer itself is the only type that has this special behavior, specifically to avoid having to deal with that stack overflow.