尝试断言时失败并出现 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);
}
原因(可能)是因为单例在子容器中由lifestylemanager处理,因此被释放。这会导致 MVC Web API 中的子容器处理出现一些问题,因此我非常希望找到解决方案。
有人知道这个问题的干净解决方案吗?
最佳答案
这确实是一个错误。 I put it in the issue tracker .已在trunk中修复,将在v3.1中修复
关于caSTLe-windsor - CaSTLe 温莎错误 : Resolving singleton through child container,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11189912/