温莎型工厂不释放儿童
我在 Windsor 2.5.1 中注册了一个工厂和组件,如下所示:
interface IFooFactory{
IFoo CreateFoo();
}
interface IFoo {
void DoSomething();
}
class ConcreteFoo : IFoo, IDisposable {
public void Dispose(){
Log.info("Going now, bye!")
}
}
container.Register(
Component.For<IFooFactory>().AsFactory().Lifestyle.PerWebRequest,
Componenet.For<IFoo>().ImplementedBy<ConcreteFoo>().Lifestyle.Transient
);
但我注意到 IFoo 的实例(每个请求可能有 100 个左右)没有被释放或没有调用它们的 dispose 方法。
我从这里的文档中假设:http://docs。 castleproject.org/Windsor.Typed-Factory-Facility-interface-based-factories.ashx 如果工厂是 PerRequest
那么将释放它创建的对象在请求的末尾。
如果我将工厂本身传递给我的组件,并调用如下所示的释放方法:
interface IFooFactory{
IFoo CreateFoo();
void Releaser(IFoo foo);
}
interface IFoo {
void DoSomething();
}
class ConcreteFoo : IFoo, IDisposable {
IFooFactory fact;
public ConcreteFoo(IFooFactory fact)....
public void DoSomething(){
fact.Releaser(this);
//Do the rest
}
public void Dispose(){
Log.info("Going now, bye!")
}
}
然后我的组件将按预期释放。关于这是否是一个错误或者我误解了什么的任何建议。我的解决方案最终有效,但没有我希望的那么好。
I have a factory and component registered in Windsor 2.5.1 like so:
interface IFooFactory{
IFoo CreateFoo();
}
interface IFoo {
void DoSomething();
}
class ConcreteFoo : IFoo, IDisposable {
public void Dispose(){
Log.info("Going now, bye!")
}
}
container.Register(
Component.For<IFooFactory>().AsFactory().Lifestyle.PerWebRequest,
Componenet.For<IFoo>().ImplementedBy<ConcreteFoo>().Lifestyle.Transient
);
But what I am noticing is the instances of IFoo (could be 100 or so per request) are not being released or having their dispose method called.
I assumed from the documentation here: http://docs.castleproject.org/Windsor.Typed-Factory-Facility-interface-based-factories.ashx that if the factory was PerRequest
then that would release the objects which it created at the end of the request.
If I pass the factory itself to my component, and call a releasing method like so:
interface IFooFactory{
IFoo CreateFoo();
void Releaser(IFoo foo);
}
interface IFoo {
void DoSomething();
}
class ConcreteFoo : IFoo, IDisposable {
IFooFactory fact;
public ConcreteFoo(IFooFactory fact)....
public void DoSomething(){
fact.Releaser(this);
//Do the rest
}
public void Dispose(){
Log.info("Going now, bye!")
}
}
Then my components get released as expected. Any advice on whether this is a bug or I am mis-understanding something. My solution works at the end of the day, but not as nice as I had hoped.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据主要问题下面的评论,Krzysztof 发布了一个更新来修复 Windsor 中的这个问题。如果您看到这些问题,请升级到 2.5.4 甚至更好的 Windsor 3(如果可以的话)。
Following the comments below the main question, Krzysztof has released an update to fix this in Windsor. If you see these issues, then either upgrade to 2.5.4 or even better, Windsor 3 if you can.