|
1 | | -# Autofac.Extras.EnterpriseLibraryConfigurator |
2 | | - |
3 | | -Microsoft Patterns and Practices Enterprise Library 5 support for using [Autofac](https://autofac.org) as the container. |
4 | | - |
5 | | -[](https://ci.appveyor.com/project/Autofac/autofac-extras-enterpriselibraryconfigurator) |
6 | | - |
7 | | -**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. |
8 | | - |
9 | | -**This package is only for EntLib 5.** Enterprise Library 6 was updated so it no longer requires an integration package and is decoupled from dependency injection. |
10 | | - |
11 | | -Please file issues and pull requests for this package in this repository rather than in the Autofac core repo. |
12 | | - |
13 | | -- [Documentation](https://autofac.readthedocs.io/en/latest/integration/entlib.html) |
14 | | -- [NuGet](https://github.com/autofac/Autofac.Extras.EnterpriseLibraryConfigurator/) |
15 | | -- [Contributing](https://autofac.readthedocs.io/en/latest/contributors.html) |
| 1 | +# Autofac.Extras.EnterpriseLibraryConfigurator |
| 2 | + |
| 3 | +Microsoft Patterns and Practices Enterprise Library 5 support for using [Autofac](https://autofac.org) as the container. |
| 4 | + |
| 5 | +[](https://ci.appveyor.com/project/Autofac/autofac-extras-enterpriselibraryconfigurator) |
| 6 | + |
| 7 | +> :warning: **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. |
| 8 | +
|
| 9 | +[The `Autofac.Extras.EnterpriseLibraryConfigurator` package](https://www.nuget.org/packages/Autofac.Extras.EnterpriseLibraryConfigurator/) provides a way to use Autofac as the backing store for dependency injection in [Microsoft Enterprise Library 5](http://entlib.codeplex.com/releases/view/43135) instead of using Unity. It does this in conjunction with the Autofac Common Service Locator implementation. |
| 10 | + |
| 11 | +> :warning: **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.** |
| 12 | +
|
| 13 | +## Using the Configurator |
| 14 | + |
| 15 | +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.Current` to use an `AutofacServiceLocator` from the Autofac Common Service Locator implementation. |
| 16 | + |
| 17 | +```csharp |
| 18 | +var builder = new ContainerBuilder(); |
| 19 | +builder.RegisterEnterpriseLibrary(); |
| 20 | +var container = builder.Build(); |
| 21 | +var csl = new AutofacServiceLocator(container); |
| 22 | +EnterpriseLibraryContainer.Current = csl; |
| 23 | +``` |
| 24 | + |
| 25 | +## Specifying a Registration Source |
| 26 | + |
| 27 | +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. |
| 28 | + |
| 29 | +```csharp |
| 30 | +var config = GetYourConfigurationSource(); |
| 31 | +var builder = new ContainerBuilder(); |
| 32 | +builder.RegisterEnterpriseLibrary(config); |
| 33 | +var container = builder.Build(); |
| 34 | +var csl = new AutofacServiceLocator(container); |
| 35 | +EnterpriseLibraryContainer.Current = csl; |
| 36 | +``` |
| 37 | + |
| 38 | +## Example |
| 39 | + |
| 40 | +There is an example project showing Enterprise Library 5 configuration along with the Exception Handling Block [in the Autofac examples repository](https://github.com/autofac/Examples/tree/v3.5.2/src/EnterpriseLibraryExample.MvcApplication). |
0 commit comments