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.castleproje开发者_开发技巧ct.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.
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.
精彩评论