开发者

Castle Windsor Releasing Typed Factory Components

I see that a breaking change made to Windsor recently is the following:

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).

I am using a auto-releasing IDisposable implementation as described here:

http://devlicio.us/b开发者_JAVA百科logs/krzysztof_kozmic/archive/2010/01/27/transparently-releasing-components-in-windsor.aspx

Because kernel.ReleaseComponent no longer releases components, the following no longer behaves as desired:

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.

How can I work around this using the latest version of Windsor?

Thanks.


Please be advised that the change you're mentioning is not part of the latest 2.5.3 release, but change in the development version of Windsor.

Also it is not related to the example you showed, which will behave exactly the same in vNext as it does now. That's an internal change which will not affect you unless you are calling out to IReleasePolicy directly.

Plus remember that that's not part of any official release and final code/behavior may be completely different.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜