Microsoft Patterns and Practices Enterprise Library 5 support for using Autofac as the container.
⚠️ MAINTENANCE MODE: This package is in maintenance-only mode. Bug fixes may be addressed and Autofac compatibility may be checked but no new features will be added.
The Autofac.Extras.EnterpriseLibraryConfigurator
package provides a way to use Autofac as the backing store for dependency injection in Microsoft Enterprise Library 5 instead of using Unity. It does this in conjunction with the Autofac Common Service Locator implementation.
⚠️ In Enterprise Library 6, Microsoft removed the tightly-coupled dependency resolution mechanisms from the application blocks so there's no more need for this configurator past Enterprise Library 5.
The simplest way to use the configurator is to set up your Enterprise Library configuration in your app.config
or web.config
and use the RegisterEnterpriseLibrary()
extension. This extension parses the configuration and performs the necessary registrations. You then need to set the ``nterpriseLibraryContainer.Currentto use an
AutofacServiceLocator` from the Autofac Common Service Locator implementation.
var builder = new ContainerBuilder();
builder.RegisterEnterpriseLibrary();
var container = builder.Build();
var csl = new AutofacServiceLocator(container);
EnterpriseLibraryContainer.Current = csl;
The RegisterEnterpriseLibrary()
extension does allow you to specify your own IConfigurationSource
so if your configuration is not in app.config
or web.config
you can still use Autofac.
var config = GetYourConfigurationSource();
var builder = new ContainerBuilder();
builder.RegisterEnterpriseLibrary(config);
var container = builder.Build();
var csl = new AutofacServiceLocator(container);
EnterpriseLibraryContainer.Current = csl;
There is an example project showing Enterprise Library 5 configuration along with the Exception Handling Block in the Autofac examples repository.