Autofac .NET Inversion of Control Container
ILifetimeScope Interface
NamespacesAutofacILifetimeScope
An ILifetimeScope tracks the instantiation of component instances. It defines a boundary in which instances are shared and configured. Disposing an ILifetimeScope will dispose the components that were resolved through it.
Declaration Syntax
C#Visual BasicVisual C++
public interface ILifetimeScope : IComponentContext, 
	IDisposable
Public Interface ILifetimeScope _
	Implements IComponentContext, IDisposable
public interface class ILifetimeScope : IComponentContext, 
	IDisposable
Members
All MembersMethodsProperties



IconMemberDescription
BeginLifetimeScope()()()
Begin a new nested scope. Component instances created via the new scope will be disposed along with it.

BeginLifetimeScope(Object)
Begin a new nested scope. Component instances created via the new scope will be disposed along with it.

BeginLifetimeScope(Action<(Of <(ContainerBuilder>)>))
Begin a new nested scope, with additional components available to it. Component instances created via the new scope will be disposed along with it.

BeginLifetimeScope(Object, Action<(Of <(ContainerBuilder>)>))
Begin a new nested scope, with additional components available to it. Component instances created via the new scope will be disposed along with it.

ComponentRegistry
Associates services with the components that provide them.
(Inherited from IComponentContext.)
Dispose()()()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
(Inherited from IDisposable.)
Disposer
The disposer associated with this ILifetimeScope. Component instances can be associated with it manually if required.

Resolve(IComponentRegistration, IEnumerable<(Of <(Parameter>)>))
Resolve an instance of the provided registration within the context.
(Inherited from IComponentContext.)
Tag
The tag applied to the ILifetimeScope.

Remarks
All long-running applications should resolve components via an ILifetimeScope. Choosing the duration of the lifetime is application- specific. The standard Autofac WCF and ASP.NET/MVC integrations are already configured to create and release ILifetimeScopes as appropriate. For example, the ASP.NET integration will create and release an ILifetimeScope per HTTP request. Most ILifetimeScope functionality is provided by extension methods on the inherited IComponentContext interface.
Examples
CopyC#
// See IContainer for definition of the container variable
using (var requestScope = container.BeginLifetimeScope())
{
    // Note that handler is resolved from requestScope, not
    // from the container:

    var handler = requestScope.Resolve<IRequestHandler>();
    handler.Handle(request);

    // When requestScope is disposed, all resources used in processing
    // the request will be released.
}
See Also

Assembly: Autofac (Module: Autofac) Version: 2.1.13.813 (2.1.13.813)