Click or drag to resize

RegistrationExtensionsPooledInstancePerMatchingLifetimeScopeTLimit, TActivatorData, TSingleRegistrationStyle Method (IRegistrationBuilderTLimit, TActivatorData, TSingleRegistrationStyle, Int32, Object)

Configure the component so that every dependent component or manual resolve within a ILifetimeScope tagged with any of the provided tags value gets the same, shared instance, retrieved from a single pool of instances shared by all lifetime scopes. When the scope ends, the instance will be returned to the pool. Dependent components in lifetime scopes that are children of the tagged scope will share the parent's instance. If no appropriately tagged scope can be found in the hierarchy an DependencyResolutionException is thrown.

Namespace:  Autofac.Pooling
Assembly:  Autofac.Pooling (in Autofac.Pooling.dll) Version: 1.0.1+e2b1e849d21d04643649a531a7435392bb1a29cd
Syntax
public static IRegistrationBuilder<TLimit, TActivatorData, TSingleRegistrationStyle> PooledInstancePerMatchingLifetimeScope<TLimit, TActivatorData, TSingleRegistrationStyle>(
	this IRegistrationBuilder<TLimit, TActivatorData, TSingleRegistrationStyle> registration,
	int maximumRetainedInstances,
	params Object[] lifetimeScopeTags
)
where TLimit : class
where TActivatorData : IConcreteActivatorData
where TSingleRegistrationStyle : SingleRegistrationStyle

Parameters

registration
Type: Autofac.BuilderIRegistrationBuilderTLimit, TActivatorData, TSingleRegistrationStyle
The registration.
maximumRetainedInstances
Type: SystemInt32
The maximum number of instances to retain in the pool.
lifetimeScopeTags
Type: SystemObject
Tags applied to matching lifetime scopes.

Type Parameters

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

Return Value

Type: IRegistrationBuilderTLimit, TActivatorData, TSingleRegistrationStyle
The registration builder.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type IRegistrationBuilderTLimit, TActivatorData, TSingleRegistrationStyle. 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

The size of the pool created with this method is equal to maximumRetainedInstances. If more instances are requested than the pool size, those instances may not be returned to the pool, but will instead be disposed/discarded.

If a component needs to perform behaviour when it is retrieved from or returned to the pool, it can implement IPooledComponent, or use the overload of this method that accepts a custom IPooledRegistrationPolicyTPooledObject.

See Also