What's the equivalent of CastleWindsor's container.Release in LightInject?

81 Views Asked by At

I saw ASP.NET Web API dependency injection in Seemann's site. It uses CastleWindsor though.

request.RegisterForDispose(
            new Release(
                () => this.container.Release(controller)));

What's the equivalent of CastleWindsor's container.Release in LightInject?

http://blog.ploeh.dk/2012/10/03/DependencyInjectioninASP.NETWebAPIwithCastleWindsor/

1

There are 1 best solutions below

0
On BEST ANSWER

There is not really a Release method in LightInject. Disposable services are registered either with the PerScopeLifetime og the PerRequestLifetime.

These services are disposed when the surrounding Scope is disposed.

container.Register<IFoo, DisposableFoo>(new PerScopeLifetime())

using(container.BeginScope())
{
    var foo = container.GetInstance<IFoo>()
} -- foo is disposed here

LightInject.WebApi provides an integration for Web Api that takes care of disposing controllers when the web request ends.