Autofac.Extensions.DependencyInjection
10.0.0
Prefix Reserved
dotnet add package Autofac.Extensions.DependencyInjection --version 10.0.0
NuGet\Install-Package Autofac.Extensions.DependencyInjection -Version 10.0.0
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="10.0.0" />
paket add Autofac.Extensions.DependencyInjection --version 10.0.0
#r "nuget: Autofac.Extensions.DependencyInjection, 10.0.0"
// Install Autofac.Extensions.DependencyInjection as a Cake Addin #addin nuget:?package=Autofac.Extensions.DependencyInjection&version=10.0.0 // Install Autofac.Extensions.DependencyInjection as a Cake Tool #tool nuget:?package=Autofac.Extensions.DependencyInjection&version=10.0.0
Autofac.Extensions.DependencyInjection
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.
Please file issues and pull requests for this package in this repository rather than in the Autofac core repo.
- Documentation - .NET Core Integration
- Documentation - ASP.NET Core Integration
- NuGet
- Contributing
- Open in Visual Studio Code
Get Started in ASP.NET Core
This quick start shows how to use the IServiceProviderFactory{T}
integration that ASP.NET Core supports to help automatically build the root service provider for you. If you want more manual control, check out the documentation for examples.
- Reference the
Autofac.Extensions.DependencyInjection
package from NuGet. - In your
Program.Main
method, where you configure theHostBuilder
, callUseAutofac
to hook Autofac into the startup pipeline. - In the
ConfigureServices
method of yourStartup
class register things into theIServiceCollection
using extension methods provided by other libraries. - In the
ConfigureContainer
method of yourStartup
class register things directly into an AutofacContainerBuilder
.
The IServiceProvider
will automatically be created for you, so there's nothing you have to do but register things.
public class Program
{
public static async Task Main(string[] args)
{
// The service provider factory used here allows for
// ConfigureContainer to be supported in Startup with
// a strongly-typed ContainerBuilder.
var host = Host.CreateDefaultBuilder(args)
.UseServiceProviderFactory(new AutofacServiceProviderFactory())
.ConfigureWebHostDefaults(webHostBuilder => {
webHostBuilder
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
})
.Build();
await host.RunAsync();
}
}
public class Startup
{
public Startup(IWebHostEnvironment env)
{
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
.AddEnvironmentVariables();
this.Configuration = builder.Build();
}
public IConfiguration Configuration { get; private set; }
// ConfigureServices is where you register dependencies. This gets
// called by the runtime before the ConfigureContainer method, below.
public void ConfigureServices(IServiceCollection services)
{
// Add services to the collection. Don't build or return
// any IServiceProvider or the ConfigureContainer method
// won't get called.
services.AddOptions();
}
// ConfigureContainer is where you can register things directly
// with Autofac. This runs after ConfigureServices so the things
// here will override registrations made in ConfigureServices.
// Don't build the container; that gets done for you. If you
// need a reference to the container, you need to use the
// "Without ConfigureContainer" mechanism shown later.
public void ConfigureContainer(ContainerBuilder builder)
{
builder.RegisterModule(new AutofacModule());
}
// Configure is where you add middleware. This is called after
// ConfigureContainer. You can use IApplicationBuilder.ApplicationServices
// here if you need to resolve things from the container.
public void Configure(
IApplicationBuilder app,
ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(this.Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
app.UseMvc();
}
}
Our ASP.NET Core integration documentation contains more information about using Autofac with ASP.NET Core.
Get Help
Need help with Autofac? We have a documentation site as well as API documentation. We're ready to answer your questions on Stack Overflow or check out the discussion forum.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 is compatible. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Autofac (>= 8.1.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.1)
-
.NETStandard 2.1
- Autofac (>= 8.1.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.1)
-
net6.0
- Autofac (>= 8.1.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.1)
-
net7.0
- Autofac (>= 8.1.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.1)
-
net8.0
- Autofac (>= 8.1.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.1)
NuGet packages (958)
Showing the top 5 NuGet packages that depend on Autofac.Extensions.DependencyInjection:
Package | Downloads |
---|---|
Volo.Abp.Autofac
Package Description |
|
Lykke.Common
Lykke common tools and utilities |
|
Autofac.AspNetCore.Multitenant
Multitenant Autofac container integration support for ASP.NET Core. |
|
TIKSN-Framework
This is a .NET Framework enhancement framework. Main features are Versioning, Finance, Currency, Foreign Exchange, Money, Pricing strategy, Telemetry, Composite Weighted Progress, Repository and Unity of Wok pattern implementation with Entity Framework Core, Network Connectivity Service and Triggering, Settings, Windows Registry configuration source, Azure Storage Repository, MongoDB Repository, NoDB Repository, Lingual and Regional Localization, Serialization, Rest Requester, Rest Repository, Dependency Injection, Composition Root Setup base classes. |
|
Autofac.Extensions.DependencyInjection.AzureFunctions
Autofac implementation of the dependency injection factory for Azure Functions. |
GitHub repositories (160)
Showing the top 5 popular GitHub repositories that depend on Autofac.Extensions.DependencyInjection:
Repository | Stars |
---|---|
ardalis/CleanArchitecture
Clean Architecture Solution Template: A starting point for Clean Architecture with ASP.NET Core
|
|
dotnet/runtime
.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
|
|
abpframework/abp
Open-source web application framework for ASP.NET Core! Offers an opinionated architecture to build enterprise software solutions with best practices on top of the .NET. Provides the fundamental infrastructure, cross-cutting-concern implementations, startup templates, application modules, UI themes, tooling and documentation.
|
|
dotnet/AspNetCore.Docs
Documentation for ASP.NET Core
|
|
Jackett/Jackett
API Support for your favorite torrent trackers
|
Version | Downloads | Last updated |
---|---|---|
10.0.0 | 831,031 | 9/2/2024 |
9.0.0 | 8,037,372 | 1/16/2024 |
8.0.0 | 27,953,751 | 5/25/2022 |
7.2.0 | 15,876,322 | 11/9/2021 |
7.2.0-preview.1 | 140,735 | 7/15/2021 |
7.1.0 | 21,217,836 | 10/29/2020 |
7.0.2 | 1,177,819 | 10/6/2020 |
7.0.1 | 321,916 | 9/28/2020 |
7.0.0 | 158,093 | 9/28/2020 |
6.0.0 | 19,879,940 | 1/27/2020 |
5.0.1 | 8,426,247 | 10/7/2019 |
5.0.0 | 1,519,795 | 9/23/2019 |
5.0.0-rc2 | 12,825 | 9/19/2019 |
5.0.0-rc1 | 25,227 | 8/29/2019 |
4.4.0 | 11,968,459 | 2/25/2019 |
4.3.1 | 5,124,222 | 11/6/2018 |
4.3.0 | 3,047,691 | 8/16/2018 |
4.2.2 | 5,389,858 | 3/20/2018 |
4.2.1 | 924,207 | 2/26/2018 |
4.2.0 | 4,964,103 | 7/19/2017 |
4.1.0 | 547,776 | 4/22/2017 |
4.0.0 | 3,143,963 | 8/9/2016 |
4.0.0-rc3-309 | 19,273 | 7/12/2016 |
4.0.0-rc3-280 | 12,540 | 6/28/2016 |
4.0.0-rc2-240 | 13,897 | 5/19/2016 |
4.0.0-rc1-177 | 33,975 | 11/19/2015 |
Release notes are at https://github.com/autofac/Autofac.Extensions.DependencyInjection/releases