{"id":18646796,"url":"https://github.com/autofac/autofac.extensions.dependencyinjection","last_synced_at":"2025-04-07T06:12:54.393Z","repository":{"id":10310769,"uuid":"65295591","full_name":"autofac/Autofac.Extensions.DependencyInjection","owner":"autofac","description":"Autofac implementation of the interfaces in Microsoft.Extensions.DependencyInjection.Abstractions, the .NET Core dependency injection abstraction.","archived":false,"fork":false,"pushed_at":"2024-09-02T03:31:14.000Z","size":274,"stargazers_count":200,"open_issues_count":0,"forks_count":48,"subscribers_count":14,"default_branch":"develop","last_synced_at":"2025-03-31T04:08:20.068Z","etag":null,"topics":["autofac","dependency-injection","netcore"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/autofac.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-08-09T13:05:41.000Z","updated_at":"2025-03-27T08:21:49.000Z","dependencies_parsed_at":"2023-10-05T00:00:09.160Z","dependency_job_id":"ea171f6b-137c-41b2-b156-7755560eda46","html_url":"https://github.com/autofac/Autofac.Extensions.DependencyInjection","commit_stats":null,"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/autofac%2FAutofac.Extensions.DependencyInjection","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/autofac%2FAutofac.Extensions.DependencyInjection/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/autofac%2FAutofac.Extensions.DependencyInjection/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/autofac%2FAutofac.Extensions.DependencyInjection/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/autofac","download_url":"https://codeload.github.com/autofac/Autofac.Extensions.DependencyInjection/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247601449,"owners_count":20964864,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["autofac","dependency-injection","netcore"],"created_at":"2024-11-07T06:22:39.738Z","updated_at":"2025-04-07T06:12:54.368Z","avatar_url":"https://github.com/autofac.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Autofac.Extensions.DependencyInjection\r\n\r\nAutofac is an [IoC container](http://martinfowler.com/articles/injection.html) 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](https://autofac.readthedocs.io/en/latest/glossary.html)*.\r\n\r\n[![Build status](https://ci.appveyor.com/api/projects/status/1mhkjcqr1ug80lra/branch/develop?svg=true)](https://ci.appveyor.com/project/Autofac/autofac-extensions-dependencyinjection/branch/develop) [![codecov](https://codecov.io/gh/Autofac/Autofac.Extensions.DependencyInjection/branch/develop/graph/badge.svg)](https://codecov.io/gh/Autofac/Autofac.Extensions.DependencyInjection)\r\n\r\nPlease file issues and pull requests for this package in this repository rather than in the Autofac core repo.\r\n\r\n- [Documentation - .NET Core Integration](https://autofac.readthedocs.io/en/latest/integration/netcore.html)\r\n- [Documentation - ASP.NET Core Integration](https://autofac.readthedocs.io/en/latest/integration/aspnetcore.html)\r\n- [NuGet](https://www.nuget.org/packages/Autofac.Extensions.DependencyInjection)\r\n- [Contributing](https://autofac.readthedocs.io/en/latest/contributors.html)\r\n- [Open in Visual Studio Code](https://open.vscode.dev/autofac/Autofac.Extensions.DependencyInjection)\r\n\r\n## Get Started in ASP.NET Core\r\n\r\nThis 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](https://autofac.readthedocs.io/en/latest/integration/aspnetcore.html).\r\n\r\n- Reference the `Autofac.Extensions.DependencyInjection` package from NuGet.\r\n- In your `Program.Main` method, where you configure the `HostBuilder`, call `UseAutofac` to hook Autofac into the startup pipeline.\r\n- In the `ConfigureServices` method of your `Startup` class register things into the `IServiceCollection` using extension methods provided by other libraries.\r\n- In the `ConfigureContainer` method of your `Startup` class register things directly into an Autofac `ContainerBuilder`.\r\n\r\nThe `IServiceProvider` will automatically be created for you, so there's nothing you have to do but *register things*.\r\n\r\n```C#\r\npublic class Program\r\n{\r\n  public static async Task Main(string[] args)\r\n  {\r\n    // The service provider factory used here allows for\r\n    // ConfigureContainer to be supported in Startup with\r\n    // a strongly-typed ContainerBuilder.\r\n    var host = Host.CreateDefaultBuilder(args)\r\n      .UseServiceProviderFactory(new AutofacServiceProviderFactory())\r\n      .ConfigureWebHostDefaults(webHostBuilder =\u003e {\r\n        webHostBuilder\r\n          .UseContentRoot(Directory.GetCurrentDirectory())\r\n          .UseIISIntegration()\r\n          .UseStartup\u003cStartup\u003e()\r\n      })\r\n      .Build();\r\n\r\n    await host.RunAsync();\r\n  }\r\n}\r\n\r\npublic class Startup\r\n{\r\n  public Startup(IWebHostEnvironment env)\r\n  {\r\n    var builder = new ConfigurationBuilder()\r\n        .SetBasePath(env.ContentRootPath)\r\n        .AddJsonFile(\"appsettings.json\", optional: true, reloadOnChange: true)\r\n        .AddJsonFile($\"appsettings.{env.EnvironmentName}.json\", optional: true)\r\n        .AddEnvironmentVariables();\r\n    this.Configuration = builder.Build();\r\n  }\r\n\r\n  public IConfiguration Configuration { get; private set; }\r\n\r\n  // ConfigureServices is where you register dependencies. This gets\r\n  // called by the runtime before the ConfigureContainer method, below.\r\n  public void ConfigureServices(IServiceCollection services)\r\n  {\r\n    // Add services to the collection. Don't build or return\r\n    // any IServiceProvider or the ConfigureContainer method\r\n    // won't get called.\r\n    services.AddOptions();\r\n  }\r\n\r\n  // ConfigureContainer is where you can register things directly\r\n  // with Autofac. This runs after ConfigureServices so the things\r\n  // here will override registrations made in ConfigureServices.\r\n  // Don't build the container; that gets done for you. If you\r\n  // need a reference to the container, you need to use the\r\n  // \"Without ConfigureContainer\" mechanism shown later.\r\n  public void ConfigureContainer(ContainerBuilder builder)\r\n  {\r\n      builder.RegisterModule(new AutofacModule());\r\n  }\r\n\r\n  // Configure is where you add middleware. This is called after\r\n  // ConfigureContainer. You can use IApplicationBuilder.ApplicationServices\r\n  // here if you need to resolve things from the container.\r\n  public void Configure(\r\n    IApplicationBuilder app,\r\n    ILoggerFactory loggerFactory)\r\n  {\r\n      loggerFactory.AddConsole(this.Configuration.GetSection(\"Logging\"));\r\n      loggerFactory.AddDebug();\r\n      app.UseMvc();\r\n  }\r\n}\r\n```\r\n\r\nOur [ASP.NET Core](https://autofac.readthedocs.io/en/latest/integration/aspnetcore.html) integration documentation contains more information about using Autofac with ASP.NET Core.\r\n\r\n## Get Help\r\n\r\n**Need help with Autofac?** We have [a documentation site](https://autofac.readthedocs.io/) as well as [API documentation](https://autofac.org/apidoc/). We're ready to answer your questions on [Stack Overflow](https://stackoverflow.com/questions/tagged/autofac) or check out the [discussion forum](https://groups.google.com/forum/#forum/autofac).\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fautofac%2Fautofac.extensions.dependencyinjection","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fautofac%2Fautofac.extensions.dependencyinjection","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fautofac%2Fautofac.extensions.dependencyinjection/lists"}