This library is a plugin for Cofoundry. For more information on getting started with Cofoundry check out the Cofoundry repository.
Autofac is an addictive Inversion of Control container for .NET Core, ASP.NET Core, .NET 4.5.1+, Universal Windows apps, and more.
This library is an Autofac implementation of the Cofoundry DI system.
The Cofoundry.Plugins.DependencyInjection.AutoFac.Web can be used to bootstrap your web application, which provides the following:
- Registers all Cofoundry and auto-registered dependencies
- Registers the MVC, WebApi and the common service locators
- Registers all MVC & WebApi controllers
Registration must be done before Cofoundry is initialized, i.e.
using Microsoft.Owin;
using Owin;
using Cofoundry.Plugins.DependencyInjection.AutoFac.Web;
using Cofoundry.Web;
[assembly: OwinStartup(typeof(MySite.Startup))]
namespace MySite
{
public class Startup
{
public void Configuration(IAppBuilder app)
{
app.UseCofoundryAutoFacIntegration();
app.UseCofoundry();
}
}
}
Outside of a web scenario, you can configure your Autofac container manually and add Cofoundry registrations using the AutoFacContainerBuilder
using AutoFac;
using Cofoundry.Plugins.DependencyInjection.AutoFac;
var autoFacBuilder = new ContainerBuilder();
var cofoundryBuilder = new AutoFacContainerBuilder(autoFacBuilder);
cofoundryBuilder.Build();