Base class for user-defined modules. Modules can add a set of releated components
to a container (Load(ContainerBuilder)) or attach cross-cutting functionality
to other components (AttachToComponentRegistration(IComponentRegistry, IComponentRegistration).
Modules are given special support in the XML configuration feature - see
http://code.google.com/p/autofac/wiki/StructuringWithModules.
| All Members | Constructors | Methods | |||
| Icon | Member | Description |
|---|---|---|
| Module()()() | Initializes a new instance of the Module class | |
| AttachToComponentRegistration(IComponentRegistry, IComponentRegistration) |
Override to attach module-specific functionality to a
component registration.
| |
| Configure(IComponentRegistry) |
Apply the module to the component registry.
| |
| Equals(Object) | (Inherited from Object.) | |
| Finalize()()() |
Allows an Object to attempt to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection.
(Inherited from Object.) | |
| GetHashCode()()() |
Serves as a hash function for a particular type.
(Inherited from Object.) | |
| GetType()()() |
Gets the Type of the current instance.
(Inherited from Object.) | |
| Load(ContainerBuilder) |
Override to add registrations to the container.
| |
| MemberwiseClone()()() |
Creates a shallow copy of the current Object.
(Inherited from Object.) | |
| ToString()()() | (Inherited from Object.) |
Provides a user-friendly way to implement IModule
via ContainerBuilder.
Defining a module:
CopyC#
Using the module:
CopyC#
public class DataAccessModule : Module { public string ConnectionString { get; set; } public override void Load(ContainerBuilder moduleBuilder) { moduleBuilder.RegisterGeneric(typeof(MyRepository<>)) .As(typeof(IRepository<>)) .InstancePerMatchingLifetimeScope(WebLifetime.Request); moduleBuilder.Register(c => new MyDbConnection(ConnectionString)) .As<IDbConnection>() .InstancePerMatchingLifetimeScope(WebLifetime.Request); } }
var builder = new ContainerBuilder(); builder.RegisterModule(new DataAccessModule { ConnectionString = "..." }); var container = builder.Build(); var customers = container.Resolve<IRepository<Customer>>();
| Object | |
| Module | |