Click or drag to resize

ContainerBuilder Class

Used to build an IContainer from component registrations.
Inheritance Hierarchy
SystemObject
  AutofacContainerBuilder

Namespace:  Autofac
Assembly:  Autofac (in Autofac.dll) Version: 4.9.1+831973f4d02fbc619921dfaa8ac0c536f60ae7a3
Syntax
public class ContainerBuilder

The ContainerBuilder type exposes the following members.

Constructors
  NameDescription
Public methodContainerBuilder
Initializes a new instance of the ContainerBuilder class.
Top
Properties
  NameDescription
Public propertyProperties
Gets the set of properties used during component registration.
Top
Methods
  NameDescription
Public methodBuild
Create a new container with the component registrations that have been made.
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodRegisterBuildCallback
Register a callback that will be invoked when the container is built.
Public methodRegisterCallback
Register a callback that will be invoked when the container is configured.
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Public methodUpdate(IComponentRegistry) Obsolete.
Configure an existing registry with the component registrations that have been made.
Public methodUpdate(IContainer) Obsolete.
Configure an existing container with the component registrations that have been made.
Public methodUpdate(IContainer, ContainerBuildOptions) Obsolete.
Configure an existing container with the component registrations that have been made and allows additional build options to be specified.
Top
Extension Methods
  NameDescription
Public Extension MethodOverrideActionFilterForTControllerOverloaded.
Sets the provided registration to act as an IOverrideFilter for the specified controller.
(Defined by RegistrationExtensions.)
Public Extension MethodOverrideActionFilterForTController(ExpressionActionTController)Overloaded.
Sets the provided registration to act as an IOverrideFilter for the specified controller action.
(Defined by RegistrationExtensions.)
Public Extension MethodOverrideAuthenticationFilterForTControllerOverloaded.
Sets the provided registration to act as an IOverrideFilter for the specified controller.
(Defined by RegistrationExtensions.)
Public Extension MethodOverrideAuthenticationFilterForTController(ExpressionActionTController)Overloaded.
Sets the provided registration to act as an IOverrideFilter for the specified controller action.
(Defined by RegistrationExtensions.)
Public Extension MethodOverrideAuthorizationFilterForTControllerOverloaded.
Sets the provided registration to act as an IOverrideFilter for the specified controller.
(Defined by RegistrationExtensions.)
Public Extension MethodOverrideAuthorizationFilterForTController(ExpressionActionTController)Overloaded.
Sets the provided registration to act as an IOverrideFilter for the specified controller action.
(Defined by RegistrationExtensions.)
Public Extension MethodOverrideExceptionFilterForTControllerOverloaded.
Sets the provided registration to act as an IOverrideFilter for the specified controller.
(Defined by RegistrationExtensions.)
Public Extension MethodOverrideExceptionFilterForTController(ExpressionActionTController)Overloaded.
Sets the provided registration to act as an IOverrideFilter for the specified controller action.
(Defined by RegistrationExtensions.)
Public Extension MethodOverrideResultFilterForTControllerOverloaded.
Sets the provided registration to act as an IOverrideFilter for the specified controller.
(Defined by RegistrationExtensions.)
Public Extension MethodOverrideResultFilterForTController(ExpressionActionTController)Overloaded.
Sets the provided registration to act as an IOverrideFilter for the specified controller action.
(Defined by RegistrationExtensions.)
Public Extension MethodOverrideWebApiActionFilterForTControllerOverloaded.
Sets the provided registration to act as an IOverrideFilter for the specified controller.
(Defined by RegistrationExtensions.)
Public Extension MethodOverrideWebApiActionFilterForTController(ExpressionActionTController)Overloaded.
Sets the provided registration to act as an IOverrideFilter for the specified controller action.
(Defined by RegistrationExtensions.)
Public Extension MethodOverrideWebApiAuthenticationFilterForTControllerOverloaded.
Sets the provided registration to act as an IOverrideFilter for the specified controller.
(Defined by RegistrationExtensions.)
Public Extension MethodOverrideWebApiAuthenticationFilterForTController(ExpressionActionTController)Overloaded.
Sets the provided registration to act as an IOverrideFilter for the specified controller action.
(Defined by RegistrationExtensions.)
Public Extension MethodOverrideWebApiAuthorizationFilterForTControllerOverloaded.
Sets the provided registration to act as an IOverrideFilter for the specified controller.
(Defined by RegistrationExtensions.)
Public Extension MethodOverrideWebApiAuthorizationFilterForTController(ExpressionActionTController)Overloaded.
Sets the provided registration to act as an IOverrideFilter for the specified controller action.
(Defined by RegistrationExtensions.)
Public Extension MethodOverrideWebApiExceptionFilterForTControllerOverloaded.
Sets the provided registration to act as an IOverrideFilter for the specified controller.
(Defined by RegistrationExtensions.)
Public Extension MethodOverrideWebApiExceptionFilterForTController(ExpressionActionTController)Overloaded.
Sets the provided registration to act as an IOverrideFilter for the specified controller action.
(Defined by RegistrationExtensions.)
Public Extension MethodPopulate(IEnumerableServiceDescriptor)Overloaded.
Populates the Autofac container builder with the set of registered service descriptors and makes IServiceProvider and IServiceScopeFactory available in the container.
(Defined by AutofacRegistration.)
Public Extension MethodPopulate(IEnumerableServiceDescriptor, Object)Overloaded.
Populates the Autofac container builder with the set of registered service descriptors and makes IServiceProvider and IServiceScopeFactory available in the container. Using this overload is incompatible with the ASP.NET Core support for IServiceProviderFactory.
(Defined by AutofacRegistration.)
Public Extension MethodRegisterT(FuncIComponentContext, T)Overloaded.
Register a delegate as a component.
(Defined by RegistrationExtensions.)
Public Extension MethodRegisterT(FuncIComponentContext, IEnumerableParameter, T)Overloaded.
Register a delegate as a component.
(Defined by RegistrationExtensions.)
Public Extension MethodRegisterAdapterTFrom, TTo(FuncTFrom, TTo)Overloaded.
Adapt all components implementing service TFrom to provide TTo using the provided adapter function.
(Defined by RegistrationExtensions.)
Public Extension MethodRegisterAdapterTFrom, TTo(FuncIComponentContext, IEnumerableParameter, TFrom, TTo)Overloaded.
Adapt all components implementing service TFrom to provide TTo using the provided adapter function.
(Defined by RegistrationExtensions.)
Public Extension MethodRegisterAdapterTFrom, TTo(FuncIComponentContext, TFrom, TTo)Overloaded.
Adapt all components implementing service TFrom to provide TTo using the provided adapter function.
(Defined by RegistrationExtensions.)
Public Extension MethodRegisterAggregateService(Type)Overloaded.
Register interfaceType as an aggregate service.
(Defined by ContainerBuilderExtensions.)
Public Extension MethodRegisterAggregateServiceTInterfaceOverloaded.
Register TInterface as an aggregate service.
(Defined by ContainerBuilderExtensions.)
Public Extension MethodRegisterApiControllers(Assembly)Overloaded.
Register types in the provided assemblies that implement IHttpController and match the default type name suffix of "Controller".
(Defined by RegistrationExtensions.)
Public Extension MethodRegisterApiControllers(String, Assembly)Overloaded.
Register types in the provided assemblies that implement IHttpController and match the provided type name suffix.
(Defined by RegistrationExtensions.)
Public Extension MethodRegisterAssemblyModules(Assembly)Overloaded.
Registers modules found in an assembly.
(Defined by ModuleRegistrationExtensions.)
Public Extension MethodRegisterAssemblyModules(Type, Assembly)Overloaded.
Registers modules found in an assembly.
(Defined by ModuleRegistrationExtensions.)
Public Extension MethodRegisterAssemblyModulesTModule(Assembly)Overloaded.
Registers modules found in an assembly.
(Defined by ModuleRegistrationExtensions.)
Public Extension MethodRegisterAssemblyTypes
Register all types in an assembly.
(Defined by RegistrationExtensions.)
Public Extension MethodRegisterComponent
Add a component to the container.
(Defined by RegistrationExtensions.)
Public Extension MethodRegisterComposablePartCatalog(ComposablePartCatalog)Overloaded.
Register a MEF catalog.
(Defined by RegistrationExtensions.)
Public Extension MethodRegisterComposablePartCatalog(ComposablePartCatalog, Service)Overloaded.
Register a MEF catalog.
(Defined by RegistrationExtensions.)
Public Extension MethodRegisterComposablePartCatalog(ComposablePartCatalog, FuncExportDefinition, IEnumerableService)Overloaded.
Register a MEF catalog.
(Defined by RegistrationExtensions.)
Public Extension MethodRegisterComposablePartDefinition
Register a MEF part definition.
(Defined by RegistrationExtensions.)
Public Extension MethodRegisterComposablePartType(Type)Overloaded.
Register a MEF-attributed type as a component.
(Defined by RegistrationExtensions.)
Public Extension MethodRegisterComposablePartType(Type, FuncExportDefinition, IEnumerableService)Overloaded.
Register a MEF-attributed type as a component.
(Defined by RegistrationExtensions.)
Public Extension MethodRegisterControllers
Register types that implement IController in the provided assemblies.
(Defined by RegistrationExtensions.)
Public Extension MethodRegisterDecorator(Type, Type, FuncIDecoratorContext, Boolean)Overloaded.
Decorate all components implementing service serviceType with decorator service decoratorType.
(Defined by RegistrationExtensions.)
Public Extension MethodRegisterDecoratorTService(FuncIComponentContext, IEnumerableParameter, TService, TService, FuncIDecoratorContext, Boolean)Overloaded.
Decorate all components implementing service TService using the provided decorator function.
(Defined by RegistrationExtensions.)
Public Extension MethodRegisterDecoratorTService(FuncTService, TService, Object, Object)Overloaded.
Decorate all components implementing service TService using the provided decorator function. The fromKey and toKey parameters must be different values.
(Defined by RegistrationExtensions.)
Public Extension MethodRegisterDecoratorTService(FuncIComponentContext, IEnumerableParameter, TService, TService, Object, Object)Overloaded.
Decorate all components implementing service TService using the provided decorator function. The fromKey and toKey parameters must be different values.
(Defined by RegistrationExtensions.)
Public Extension MethodRegisterDecoratorTService(FuncIComponentContext, TService, TService, Object, Object)Overloaded.
Decorate all components implementing service TService using the provided decorator function. The fromKey and toKey parameters must be different values.
(Defined by RegistrationExtensions.)
Public Extension MethodRegisterDecoratorTDecorator, TService(FuncIDecoratorContext, Boolean)Overloaded.
Decorate all components implementing service TService with decorator service TDecorator.
(Defined by RegistrationExtensions.)
Public Extension MethodCode exampleRegisterEnterpriseLibraryOverloaded.
Adds dependency registrations from the default Enterprise Library configuration source to the provided Autofac container builder.
(Defined by EnterpriseLibraryRegistrationExtensions.)
Public Extension MethodCode exampleRegisterEnterpriseLibrary(IConfigurationSource)Overloaded.
Adds dependency registrations from a specified Enterprise Library configuration source to the provided Autofac container builder.
(Defined by EnterpriseLibraryRegistrationExtensions.)
Public Extension MethodRegisterFilterProvider
Registers the AutofacFilterProvider.
(Defined by RegistrationExtensions.)
Public Extension MethodRegisterGeneratedFactory(Type)Overloaded.
Registers a factory delegate.
(Defined by RegistrationExtensions.)
Public Extension MethodRegisterGeneratedFactory(Type, Service)Overloaded.
Registers a factory delegate.
(Defined by RegistrationExtensions.)
Public Extension MethodRegisterGeneratedFactoryTDelegateOverloaded.
Registers a factory delegate.
(Defined by RegistrationExtensions.)
Public Extension MethodRegisterGeneratedFactoryTDelegate(Service)Overloaded.
Registers a factory delegate.
(Defined by RegistrationExtensions.)
Public Extension MethodRegisterGeneric
Register an un-parameterised generic type, e.g. Repository<>. Concrete types will be made as they are requested, e.g. with Resolve<Repository<int>>().
(Defined by RegistrationExtensions.)
Public Extension MethodRegisterGenericDecorator(Type, Type, FuncIDecoratorContext, Boolean)Overloaded.
Decorate all components implementing open generic service serviceType.
(Defined by RegistrationExtensions.)
Public Extension MethodRegisterGenericDecorator(Type, Type, Object, Object)Overloaded.
Decorate all components implementing open generic service decoratedServiceType. The fromKey and toKey parameters must be different values.
(Defined by RegistrationExtensions.)
Public Extension MethodRegisterHttpRequestMessage
Makes the current HttpRequestMessage resolvable through the dependency scope.
(Defined by RegistrationExtensions.)
Public Extension MethodRegisterHubs
Register types that implement IHub in the provided assemblies.
(Defined by RegistrationExtensions.)
Public Extension MethodRegisterInstanceT
Register an instance as a component.
(Defined by RegistrationExtensions.)
Public Extension MethodRegisterMetadataRegistrationSources
Registers the LazyWithMetadataRegistrationSource and StronglyTypedMetadataRegistrationSource registration sources.
(Defined by RegistrationExtensions.)
Public Extension MethodRegisterModelBinderProvider (Defined by RegistrationExtensions.)
Public Extension MethodRegisterModelBinders
Register types that implement IModelBinder in the provided assemblies and have a ModelBinderTypeAttribute.
(Defined by RegistrationExtensions.)
Public Extension MethodRegisterModule(IModule)Overloaded.
Add a module to the container.
(Defined by ModuleRegistrationExtensions.)
Public Extension MethodRegisterModuleTModuleOverloaded.
Add a module to the container.
(Defined by ModuleRegistrationExtensions.)
Public Extension MethodRegisterSource(IRegistrationSource)Overloaded.
Add a registration source to the container.
(Defined by RegistrationExtensions.)
Public Extension MethodRegisterSourceTRegistrationSourceOverloaded.
Add a registration source to the container.
(Defined by SourceRegistrationExtensions.)
Public Extension MethodRegisterType(Type)Overloaded.
Register a component to be created through reflection.
(Defined by RegistrationExtensions.)
Public Extension MethodRegisterTypeTImplementerOverloaded.
Register a component to be created through reflection.
(Defined by RegistrationExtensions.)
Public Extension MethodCode exampleRegisterTypeRegistration
Registers an Enterprise Library type registration with Autofac.
(Defined by EnterpriseLibraryRegistrationExtensions.)
Public Extension MethodRegisterTypes
Register the types in a list.
(Defined by RegistrationExtensions.)
Public Extension MethodRegisterWebApiFilterProvider (Defined by RegistrationExtensions.)
Public Extension MethodRegisterWebApiModelBinderProvider (Defined by RegistrationExtensions.)
Public Extension MethodRegisterWebApiModelBinders
Register types that implement IModelBinder in the provided assemblies.
(Defined by RegistrationExtensions.)
Top
Remarks
Most ContainerBuilder functionality is accessed via extension methods in RegistrationExtensions.
Examples
var builder = new ContainerBuilder();

builder.RegisterType<Logger>()
    .As<ILogger>()
    .SingleInstance();

builder.Register(c => new MessageHandler(c.Resolve<ILogger>()));

var container = builder.Build();
// resolve components from container...
See Also