2011-02-18 60 views
0

我看到温莎做出重大更改最近如下:城堡温莎释放类型化厂元器件

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解决此问题?

谢谢。

回答

2

请注意,您提到的更改是而不是是最新2.5.3发行版的一部分,但在Windsor的开发版中有所变化。

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

还记得那是不是任何官方发布和最终代码/行为的一部分可能会完全不同。

+0

明白了。谢谢。我如何下载2.5.3版本的特定源代码?编译自己的原因:基本上,我使用SL编译的Windsor版本来从完整的.NET 4.0项目中引用(因为我有一个引用Windsor的SL项目,我想从我的.NET项目中引用)和I想从Windsor中删除System.Windows引用。只需要一个地方,我用一些简单的动态关键字/反射来代替它。除了上面提到的问题之外,所有工作都正常。 – Jeff 2011-02-20 13:57:47