Last edited Oct 2, 2008 at 5:02 AM by ctavares, version 2

Comments

alonzofox Jan 20, 2011 at 12:27 AM 
FYI... I figured out the stack overflow problem. The service locator keeps a reference to the unity container it was created with. Later, when the locator is disposed, it disposes the container. Since the locator was added without the externally controlled lifetime manager, it creates a recursive loop resulting in the exception. All I needed to do was change from the default lifetime manager like so:

using(var contrainer = new UnityContrainer())
{
container.RegisterInstance<IServiceLocator>(new UnityServiceLocator(container), new ExternallyControlledLifetimeManager());
}

alonzofox Jan 15, 2011 at 4:04 AM 
I noticed that UnityServiceLocator and UnityContainer both implement IDisposable. I have them in using statements as recomended, but it seems that pretty much any arragement I can think of results in a StackOverflowException upon disposal. I tried the following:

using (var container = new UnityContainer())
using (var locator = new UnityServiceLocator(container))
{
container.RegisterInstance<IServiceLocator>(locator);
}

using(var container = new UnityContainer())
{
container.RegisterInstance<IServiceLocator>(new UnityServiceLocator(container));
}

And a few others... eventually I just manually injected the IServiceLocator dependency instead of havig the container do it. I'm sure I'm doing something wrong here, is this a creating a circular reference er something? Thanks!

ctavares Jan 6, 2010 at 7:11 PM 
Unity lets you resolve unregistered concrete types, and will try to (and often succeeds at) create them. It's not an error. I'm not sure what your "null singleton object" comment means?

sdhebert Jan 3, 2010 at 3:08 AM 
When an unregistered type is requested, an 'ActivationException' is not thrown

I would make the change to the unity project, but it appears that Unity is not throwing an exception. Therefore it could be a situation where a user is allowed to register a null singleton object? Any thoughts on this?

nicknguyen Jan 19, 2009 at 2:07 PM 
Since this is a unsigned project, what licensing terms apply for strong naming the UntiyAdapter project, rebuilding it and distribution?