EDIT:
I’ve completed rephrased the question as I’ve been able to simplify my problem down to the following:
var container = new WindsorContainer();
container.Register(Component.For<IFoo>().ImplementedBy<Foo>().LifeStyle.Singleton);
var foo = container.Resolve<IFoo>();
container.Kernel.ReleaseComponent(foo);
var foo2 = container.Resolve<IFoo>();
Assert.IsTrue(foo != foo2) // this fails
public interface IFoo : IDisposable { }
public class Foo : IFoo {
public void Dispose()
{
}
}
I must be doing something really stupid here…any idea what?
Basically, what I’m trying to accomplish here is for a all resolutions of a component to return the same instance for some period of time (a scope). If there is a better way of accomplishing this, I’m certainly open to it.
EDIT:
Ok, so I RTFM and apparently this is by design. Is the best way of accomplishing what I want here still a custom lifestyle manager?
Thanks.
Your
FooisPerThread. That means you will get a new instance… if you request it on another thread. If I understand you correctly, the issue is with the lifestyle you’ve chosen, not how you release components.