RegistrationExtensionsRegisterModelBinders Method |
Namespace: Autofac.Integration.Mvc
public static IRegistrationBuilder<Object, ScanningActivatorData, DynamicRegistrationStyle> RegisterModelBinders( this ContainerBuilder builder, params Assembly[] modelBinderAssemblies )
Exception | Condition |
---|---|
ArgumentNullException | Thrown if builder or modelBinderAssemblies is . |
The declarative mechanism of registering model binders with Autofac is through use of this method and the ModelBinderTypeAttribute. If you would like more imperative control over registration for your model binders, see the AsModelBinderForTypesTLimit, TActivatorData, TRegistrationStyle(IRegistrationBuilderTLimit, TActivatorData, TRegistrationStyle, Type) method.
The two mechanisms are mutually exclusive. If you register a model binder using AsModelBinderForTypesTLimit, TActivatorData, TRegistrationStyle(IRegistrationBuilderTLimit, TActivatorData, TRegistrationStyle, Type) 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.
This method only registers types that implement IModelBinder and are marked with the ModelBinderTypeAttribute. The model binder must have the attribute because the AutofacModelBinderProvider uses the associated metadata - from the attribute(s) - to resolve the binder based on model type. If there aren't any attributes, there won't be any metadata, so the model binder will be technically registered but will never actually be resolved.
If your model is not marked with the attribute, or if you don't want to use attributes, use the AsModelBinderForTypesTLimit, TActivatorData, TRegistrationStyle(IRegistrationBuilderTLimit, TActivatorData, TRegistrationStyle, Type) extension instead.