Click or drag to resize

RegistrationExtensionsAutoActivateTLimit, TActivatorData, TRegistrationStyle Method

Wraps a registration in an implicit IStartable and automatically activates the registration after the container is built.

Namespace:  Autofac
Assembly:  Autofac (in Autofac.dll) Version: 6.0.0+39696a967e8826f7f1ebc8c1ff4523c9dd75abe0
Syntax
public static IRegistrationBuilder<TLimit, TActivatorData, TRegistrationStyle> AutoActivate<TLimit, TActivatorData, TRegistrationStyle>(
	this IRegistrationBuilder<TLimit, TActivatorData, TRegistrationStyle> registration
)

Parameters

registration
Type: Autofac.BuilderIRegistrationBuilderTLimit, TActivatorData, TRegistrationStyle
Registration to set release action for.

Type Parameters

TLimit
Registration limit type.
TActivatorData
Activator data type.
TRegistrationStyle
Registration style.

Return Value

Type: IRegistrationBuilderTLimit, TActivatorData, TRegistrationStyle
A registration builder allowing further configuration of the component.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type IRegistrationBuilderTLimit, TActivatorData, TRegistrationStyle. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).
Remarks

While you can implement an IStartable to perform some logic at container build time, sometimes you need to just activate a registered component and that's it. This extension allows you to automatically activate a registration on container build. No additional logic is executed and the resolved instance is not held so container disposal will end up disposing of the instance.

Depending on how you register the lifetime of the component, you may get an exception when you build the container - components that are scoped to specific lifetimes (like ASP.NET components scoped to a request lifetime) will fail to resolve because the appropriate lifetime is not available.

See Also