尝试断言时失败并出现ObjectDisposedException:
[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);
}
原因是(可能)因为单身人士由儿童容器中的生活方式管理者处理,因此被处置。这导致了MVC Web API中子容器处理的一些问题,所以我非常渴望找到解决方案。
有没有人知道这个问题的干净解决方案?