【问题标题】:Castle Windsor Releasing Typed Factory ComponentsCastle Windsor 发布类型化工厂组件
【发布时间】:2011-02-18 15:08:56
【问题描述】:

我看到最近对 Windsor 做出的重大改变如下:

change - IReleasePolicy interface has a new method: IReleasePolicy CreateSubPolicy(); usage of
    sub-policies changes how typed factories handle out-of-band-release of components (see
    description)

    impact - medium
    fixability - easy

    description - This was added as an attempt to enable more fine grained lifetime scoping (mostly
        for per-typed-factory right now, but in the future also say - per-window in client app).
        As a side-effect of that (and change to release policy behavior described above) it is no
        longer possible to release objects resolved via typed factories, using container.Release.
        As the objects are now tracked only in the scope of the factory they will be released only
        if a call to factory releasing method is made, or when the factory itself is released.

    fix - Method should return new object that exposes the same behavior as the 'parent' usually it
        is just best to return object of the same type (as the built-in release policies do).

我正在使用此处所述的自动释放 IDisposable 实现:

http://devlicio.us/blogs/krzysztof_kozmic/archive/2010/01/27/transparently-releasing-components-in-windsor.aspx

由于 kernel.ReleaseComponent 不再发布组件,因此以下行为不再符合预期:

using (var instance = container.Resolve<Func<IMyDisposable>>()()) 
{
...
} // my interceptor gets called here, but instance is not disposed because the Kernel's ReleasePolicy doesn't track it anymore.

如何使用最新版本的 Windsor 解决此问题?

谢谢。

【问题讨论】:

    标签: .net castle-windsor aop


    【解决方案1】:

    请注意,您提到的更改不是最新 2.5.3 版本的一部分,而是 Windsor 开发版本的更改。

    此外,它与您展示的示例无关,它在 vNext 中的行为与现在完全相同。这是一个内部更改,除非您直接呼叫 IReleasePolicy,否则不会影响您。

    另外请记住,这不是任何官方版本的一部分,最终代码/行为可能完全不同。

    【讨论】:

    • 知道了。谢谢。如何下载 2.5.3 版本的特定源?自己编译的原因:基本上,我使用 SL 编译的 Windsor 版本作为完整 .NET 4.0 项目的参考(因为我有一个 SL 项目,它引用了我想从我的 .NET 项目中引用的 Windsor)并且我想从 Windsor 中删除 System.Windows 引用。只有一个地方需要它,我用一些简单的动态关键字/反射替换它。除上述问题外,一切正常。
    • 每个版本的存储库中都有一个标签。
    猜你喜欢
    • 1970-01-01
    • 2012-02-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多