温莎型工厂不释放儿童

发布于 2024-12-06 21:57:28 字数 1305 浏览 1 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

少女七分熟 2024-12-13 21:57:28

根据主要问题下面的评论,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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文