简体   繁体   中英

Castle Windsor Releasing Components

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 Foo is PerThread . 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM