Autofac is an IoC container for Microsoft .NET. It manages the dependencies between classes so that applications stay easy to change as they grow in size and complexity. This is achieved by treating regular .NET classes as components.
You can get Autofac by grabbing the latest NuGet package. There are several application integration and extended functionality packages to choose from. If you're feeling adventurous, continuous integration builds are on MyGet.
Our Getting Started tutorial walks you through integrating Autofac with a simple application and gives you some starting points for learning more.
Super-duper quick start:
Register components with a
ContainerBuilder and then build the component container.
var builder = new ContainerBuilder(); builder.Register(c => new TaskController(c.Resolve<ITaskRepository>())); builder.RegisterType<TaskController>(); builder.RegisterInstance(new TaskController()); builder.RegisterAssemblyTypes(controllerAssembly); var container = builder.Build();
Resolve services from a lifetime scope - either the container or a nested scope:
var taskController = container.Resolve<TaskController>();
There is a growing number of application integration libraries that make using Autofac with your application a snap. Support for several popular frameworks is also available through the "Extras" packages.
Autofac is licensed under the MIT license, so you can comfortably use it in commercial applications (we still love contributions though).
File issues in the repo with the associated feature/code.
- Autofac - Core dependency resolution and common functions (this repo).
- Autofac.AspNetCore.Multitenant - Multitenant DI support for ASP.NET Core applications.
- Autofac.Configuration - JSON/XML file-based configuration support.
- Autofac.Diagnostics.DotGraph - Diagnostics support to enable DOT graph visualization of resolve requests.
- Autofac.Extensions.DependencyInjection - .NET Core integration for Autofac.
- Autofac.Extras.AggregateService - Dynamic aggregate service implementation generation.
- Autofac.Extras.AttributeMetadata - Metadata scanning/filtering through attributes.
- Autofac.Extras.CommonServiceLocator - Common Service Locator implementation backed by Autofac.
- Autofac.Extras.DynamicProxy - Decorators and interceptors.
- Autofac.Extras.FakeItEasy - FakeItEasy mocking framework integration.
- Autofac.Extras.Moq - Moq mocking framework integration.
- Autofac.Mef - MEF catalog integration.
- Autofac.Multitenant - Multitenant dependency resolution support.
- Autofac.Multitenant.Wcf - Multitenant WCF service hosting.
- Autofac.Mvc - ASP.NET MVC integration.
- Autofac.Mvc.Owin - OWIN support for ASP.NET MVC.
- Autofac.Owin - Core OWIN support - shared middleware for request lifetime integration.
- Autofac.Pooling - Support for pooled instance lifetime scopes.
- Autofac.ServiceFabric - Application integration for Service Fabric services.
- Autofac.SignalR - Application integration for SignalR.
- Autofac.Wcf - WCF service hosting.
- Autofac.Web - ASP.NET web forms integration.
- Autofac.WebApi - Application integration for Web API.
- Autofac.WebApi.Owin - OWIN support for Web API.
Autofac is supported by AWS. Thanks for your contribution!
Refer to the Contributor Guide for setting up and building Autofac source.
You can also open this repository right now in VS Code.