snipervld.Autofac.Extensions.DependencyInjection 5.0.1-keyed-support-v2

This is a prerelease version of snipervld.Autofac.Extensions.DependencyInjection.
dotnet add package snipervld.Autofac.Extensions.DependencyInjection --version 5.0.1-keyed-support-v2
NuGet\Install-Package snipervld.Autofac.Extensions.DependencyInjection -Version 5.0.1-keyed-support-v2
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="snipervld.Autofac.Extensions.DependencyInjection" Version="5.0.1-keyed-support-v2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add snipervld.Autofac.Extensions.DependencyInjection --version 5.0.1-keyed-support-v2
#r "nuget: snipervld.Autofac.Extensions.DependencyInjection, 5.0.1-keyed-support-v2"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install snipervld.Autofac.Extensions.DependencyInjection as a Cake Addin
#addin nuget:?package=snipervld.Autofac.Extensions.DependencyInjection&version=5.0.1-keyed-support-v2&prerelease

// Install snipervld.Autofac.Extensions.DependencyInjection as a Cake Tool
#tool nuget:?package=snipervld.Autofac.Extensions.DependencyInjection&version=5.0.1-keyed-support-v2&prerelease

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

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.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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 was computed.  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 was computed.  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 was computed. 
.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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
5.0.1-keyed-support-v2 94 9/15/2023
5.0.1-keyed-support 62 9/15/2023