Click or drag to resize

RegistrationExtensionsAsModelBinderForTypesTLimit, TActivatorData, TRegistrationStyle Method

Sets a provided registration to act as an IModelBinder for the specified list of types.

Namespace:  Autofac.Integration.Mvc
Assembly:  Autofac.Integration.Mvc (in Autofac.Integration.Mvc.dll) Version: 6.0.0+106fe194fc419c09f32d39119967f68798cc6895
public static IRegistrationBuilder<TLimit, TActivatorData, TRegistrationStyle> AsModelBinderForTypes<TLimit, TActivatorData, TRegistrationStyle>(
	this IRegistrationBuilder<TLimit, TActivatorData, TRegistrationStyle> registration,
	params Type[] types
where TActivatorData : IConcreteActivatorData
where TRegistrationStyle : SingleRegistrationStyle


Type: Autofac.BuilderIRegistrationBuilderTLimit, TActivatorData, TRegistrationStyle
The registration for the type or object instance that will act as the model binder.
Type: SystemType
The list of model Type for which the registration should be a model binder.

Type Parameters

Registration limit type.
Activator data type.
Registration style.

Return Value

Type: IRegistrationBuilderTLimit, TActivatorData, TRegistrationStyle
An Autofac registration that can be modified as needed.

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).
ArgumentNullException Thrown if registration or types is .
ArgumentException Thrown if types is empty or contains all values.

The declarative mechanism of registering model binders with Autofac is through use of RegisterModelBinders(ContainerBuilder, Assembly) and the ModelBinderTypeAttribute. This method is an imperative alternative.

The two mechanisms are mutually exclusive. If you register a model binder using RegisterModelBinders(ContainerBuilder, Assembly) and register the same model binder with this method, the results are not automatically merged together - standard dependency registration/resolution rules will be used to manage the conflict.

Any values provided in types will be removed prior to registration.

See Also