Click or drag to resize

LifetimeScopeBeginLifetimeScope Method (Object, ActionContainerBuilder)

Begin a new tagged sub-scope, with additional components available to it. Component instances created via the new scope will be disposed along with it.

Namespace:  Autofac.Core.Lifetime
Assembly:  Autofac (in Autofac.dll) Version: 6.0.0+39696a967e8826f7f1ebc8c1ff4523c9dd75abe0
Syntax
public ILifetimeScope BeginLifetimeScope(
	Object tag,
	Action<ContainerBuilder> configurationAction
)

Parameters

tag
Type: SystemObject
The tag applied to the ILifetimeScope.
configurationAction
Type: SystemActionContainerBuilder
Action on a ContainerBuilder that adds component registrations visible only in the new scope.

Return Value

Type: ILifetimeScope
A new lifetime scope.

Implements

ILifetimeScopeBeginLifetimeScope(Object, ActionContainerBuilder)
Examples
IContainer cr = // ...
using (var lifetime = cr.BeginLifetimeScope("unitOfWork", builder => {
        builder.RegisterType<Foo>();
        builder.RegisterType<Bar>().As<IBar>(); })
{
    var foo = lifetime.Resolve<Foo>();
}
See Also