All Projects → autofac → Autofac.extensions.dependencyinjection

autofac / Autofac.extensions.dependencyinjection

Licence: mit
Autofac implementation of the interfaces in Microsoft.Extensions.DependencyInjection.Abstractions, the .NET Core dependency injection abstraction.

Projects that are alternatives of or similar to Autofac.extensions.dependencyinjection

DotNetDynamicInjector
💉 Dynamically reference external dlls without the need to add them to the project. Leave your project with low dependency and allowing specific dlls according to your business rule or database parameters.
Stars: ✭ 18 (-81.63%)
Mutual labels:  dependency-injection, netcore
Autofac
An addictive .NET IoC container
Stars: ✭ 3,713 (+3688.78%)
Mutual labels:  netcore, dependency-injection
netcore-wcf-service-proxy
Example of consuming multiple WCF services using a proxy implementation in a ASP.NET Core Web-application.
Stars: ✭ 42 (-57.14%)
Mutual labels:  dependency-injection, netcore
Dryioc
DryIoc is fast, small, full-featured IoC Container for .NET
Stars: ✭ 555 (+466.33%)
Mutual labels:  netcore, dependency-injection
Blog.core
💖 ASP.NET Core 6.0 全家桶教程,前后端分离后端接口,vue教程姊妹篇,官方文档:
Stars: ✭ 3,542 (+3514.29%)
Mutual labels:  netcore, dependency-injection
Singularity
A extremely fast ioc container for high performance applications
Stars: ✭ 63 (-35.71%)
Mutual labels:  netcore, dependency-injection
Module Shop Mini Program
一个基于 .NET Core构建的简单、跨平台、模块化的商城系统
Stars: ✭ 89 (-9.18%)
Mutual labels:  netcore
Aspectcore Framework
AspectCore is an AOP-based cross platform framework for .NET Standard.
Stars: ✭ 1,318 (+1244.9%)
Mutual labels:  netcore
Jab
C# Source Generator based dependency injection container implementation.
Stars: ✭ 87 (-11.22%)
Mutual labels:  dependency-injection
Fastify Decorators
Set of Typescript decorators to build Fastify server with controllers, services and hooks
Stars: ✭ 85 (-13.27%)
Mutual labels:  dependency-injection
Bruteshark
Network Analysis Tool
Stars: ✭ 1,335 (+1262.24%)
Mutual labels:  netcore
Efcoreinaction Secondedition
Supporting repo to go with book "Entity Framework Core in Action", second edition
Stars: ✭ 96 (-2.04%)
Mutual labels:  netcore
Filecontextcore
FileContextCore is a "Database"-Provider for Entity Framework Core and adds the ability to store information in files instead of being limited to databases.
Stars: ✭ 91 (-7.14%)
Mutual labels:  netcore
Container Ioc
Inversion of Control container & Dependency Injection for Javascript and Node.js apps powered by Typescript.
Stars: ✭ 89 (-9.18%)
Mutual labels:  dependency-injection
Bootique
Bootique is a minimally opinionated platform for modern runnable Java apps.
Stars: ✭ 1,326 (+1253.06%)
Mutual labels:  dependency-injection
Datakernel
Alternative Java platform, built from the ground up - with its own async I/O core and DI. Ultra high-performance, simple and minimalistic - redefines server-side programming, web-development and highload!
Stars: ✭ 87 (-11.22%)
Mutual labels:  dependency-injection
Agentframework
An elegant & efficient TypeScript metaprogramming API to build software agents
Stars: ✭ 97 (-1.02%)
Mutual labels:  dependency-injection
Alfa
Effortless React State Management.
Stars: ✭ 86 (-12.24%)
Mutual labels:  dependency-injection
Mvpandroid
Sample app to demonstrate MVP (Model - View - Presenter) architecture in android
Stars: ✭ 91 (-7.14%)
Mutual labels:  dependency-injection
Noorm.net
Fast, modern and extendible C# Data Access library
Stars: ✭ 96 (-2.04%)
Mutual labels:  netcore

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.

Build status codecov

Please file issues and pull requests for this package in this repository rather than in the Autofac core repo.

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 the HostBuilder, call UseAutofac to hook Autofac into the startup pipeline.
  • In the ConfigureServices method of your Startup class register things into the IServiceCollection using extension methods provided by other libraries.
  • In the ConfigureContainer method of your Startup class register things directly into an Autofac ContainerBuilder.

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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].