caSTLe-windsor - CaSTLe 温莎错误 : Resolving singleton through child container

标签 castle-windsor asp.net-web-api castle

尝试断言时失败并出现 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/

相关文章:

caSTLe-windsor - 城堡温莎 : Get all names of registered components for a specific interface

asp.net-web-api - ASP.NET Web API 自定义 PUT 方法不起作用(返回 404)

asp.net-mvc-4 - 从 ASP.Net MVC 4 Web 应用程序使用 ASP.Net Web API

.net - NET40-RequiresCaSTLe 和 NET40 版本的 Moq 有什么区别?

.net - 温莎城堡 : Registering all implementations of an interface having the same constructor parameter

windows-phone-7 - NuGet 中的 CaSTLe Windsor 引用在 Windows Phone 7 项目中不起作用

asp.net-mvc - 项目 Windsor - 存储库扩展 DataContext

ninject - transient 与每个 Web 请求的生活方式,什么构成 Web 请求?

javascript - 使用 vanilla Javascript 将字符串列表发送到 ASP.net api Controller

inversion-of-control - 如何用城堡温莎覆盖组件?