Module Class |
Namespace: Autofac
The Module type exposes the following members.
Name | Description | |
---|---|---|
ThisAssembly |
Gets the assembly in which the concrete module type is located. To avoid bugs whereby deriving from a module will
change the target assembly, this property can only be used by modules that inherit directly from
Module.
|
Name | Description | |
---|---|---|
AttachToComponentRegistration |
Override to attach module-specific functionality to a
component registration.
| |
AttachToRegistrationSource |
Override to perform module-specific processing on a registration source.
| |
Configure |
Apply the module to the component registry.
| |
Equals | Determines whether the specified object is equal to the current object. (Inherited from Object.) | |
Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) | |
GetHashCode | Serves as the default hash function. (Inherited from Object.) | |
GetType | Gets the Type of the current instance. (Inherited from Object.) | |
Load |
Override to add registrations to the container.
| |
MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) | |
ToString | Returns a string that represents the current object. (Inherited from Object.) |
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>>();