This fails with an ObjectDisposedException when trying to assert:
[Test]
public void Resolve_SingletonAndDisposeChildContainer_ShouldNotDisposeSingleton()
{
// arrange
var container = new WindsorContainer();
container.AddFacility<TypedFactoryFacility>();
container.Register(Component.For<ISomeFactory>().AsFactory());
container.Register(Component.For<A>());
// uncomment the line below and the test will not fail
//container.Resolve<ISomeFactory>();
var childContainer = new WindsorContainer();
container.AddChildContainer(childContainer);
// act
var someFactory = childContainer.Resolve<ISomeFactory>();
container.RemoveChildContainer(childContainer);
childContainer.Dispose();
someFactory = container.Resolve<ISomeFactory>();
// assert
Assert.That(someFactory.Create(), Is.Not.Null);
}
The reason is (probably) because the singleton is handled by the lifestylemanager in the child container and is therefore disposed. This is causing some issues with child-container handling in the MVC Web API, so I am really keen on finding a solution.
Does anyone know of a clean solution to this problem?
This is indeed a bug. I put it in the issue tracker. It is fixed in trunk and will be fixed in v3.1