Autofac.Configuration 7.0.0

Prefix Reserved
dotnet add package Autofac.Configuration --version 7.0.0                
NuGet\Install-Package Autofac.Configuration -Version 7.0.0                
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="Autofac.Configuration" Version="7.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Autofac.Configuration --version 7.0.0                
#r "nuget: Autofac.Configuration, 7.0.0"                
#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 Autofac.Configuration as a Cake Addin
#addin nuget:?package=Autofac.Configuration&version=7.0.0

// Install Autofac.Configuration as a Cake Tool
#tool nuget:?package=Autofac.Configuration&version=7.0.0                

Autofac.Configuration

Configuration support for Autofac.

Build status

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

Quick Start

The basic steps to getting configuration set up with your application are:

  1. Set up your configuration in JSON or XML files that can be read by Microsoft.Extensions.Configuration.
    • JSON configuration uses Microsoft.Extensions.Configuration.Json
    • XML configuration uses Microsoft.Extensions.Configuration.Xml
  2. Build the configuration using the Microsoft.Extensions.Configuration.ConfigurationBuilder.
  3. Create a new Autofac.Configuration.ConfigurationModule and pass the built Microsoft.Extensions.Configuration.IConfiguration into it.
  4. Register the Autofac.Configuration.ConfigurationModule with your container.

A configuration file with some simple registrations looks like this:

{
  "defaultAssembly": "Autofac.Example.Calculator",
  "components": [{
    "type": "Autofac.Example.Calculator.Addition.Add, Autofac.Example.Calculator.Addition",
    "services": [{
      "type": "Autofac.Example.Calculator.Api.IOperation"
    }],
    "injectProperties": true
  }, {
    "type": "Autofac.Example.Calculator.Division.Divide, Autofac.Example.Calculator.Division",
    "services": [{
      "type": "Autofac.Example.Calculator.Api.IOperation"
    }],
    "parameters": {
      "places": 4
    }
  }]
}

JSON is cleaner and easier to read, but if you prefer XML, the same configuration looks like this:

<?xml version="1.0" encoding="utf-8" ?>
<autofac defaultAssembly="Autofac.Example.Calculator">
    <components name="0">
        <type>Autofac.Example.Calculator.Addition.Add, Autofac.Example.Calculator.Addition</type>
        <services name="0" type="Autofac.Example.Calculator.Api.IOperation" />
        <injectProperties>true</injectProperties>
    </components>
    <components name="1">
        <type>Autofac.Example.Calculator.Division.Divide, Autofac.Example.Calculator.Division</type>
        <services name="0" type="Autofac.Example.Calculator.Api.IOperation" />
        <injectProperties>true</injectProperties>
        <parameters>
            <places>4</places>
        </parameters>
    </components>
</autofac>

Note the ordinal "naming" of components and services in XML - this is due to the way Microsoft.Extensions.Configuration handles ordinal collections (arrays).

Build up your configuration and register it with the Autofac ContainerBuilder like this:

// Add the configuration to the ConfigurationBuilder.
var config = new ConfigurationBuilder();
// config.AddJsonFile comes from Microsoft.Extensions.Configuration.Json
// config.AddXmlFile comes from Microsoft.Extensions.Configuration.Xml
config.AddJsonFile("autofac.json");

// Register the ConfigurationModule with Autofac.
var module = new ConfigurationModule(config.Build());
var builder = new ContainerBuilder();
builder.RegisterModule(module);

Check out the Autofac configuration documentation for more information.

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (42)

Showing the top 5 NuGet packages that depend on Autofac.Configuration:

Package Downloads
Autofac.Extras.AboditNLP

AboditNLP integration for Autofac

Baseclass.Contrib.SpecFlow.Selenium.NUnit

Configures SpecFlow to be able to easily use Selenium for WebTesting. Makes it possible to annotate a scenario with the browser it's supposed to work with. Contains SauceLabs IWebDriver implementation which has utility methods to update test status.

Unickq.SpecFlow.Selenium

Test class generator to drive automated web ui tests with Selenium and SpecFlow 2.4 Works with BrowserStack, SauceLabs, TestingBot, CrossbrowserTesting and any WebDriver grid. Based on Baseclass.Contrib.SpecFlow.Selenium.NUnit.

TayText.NancyEx.Standard

Package Description

Gaia.Core.IoC.Autofac

Package Description

GitHub repositories (10)

Showing the top 5 popular GitHub repositories that depend on Autofac.Configuration:

Repository Stars
OrchardCMS/Orchard
Orchard is a free, open source, community-focused Content Management System built on the ASP.NET MVC platform.
microsoft/dotnet-apiport
This repo contains .NET Portability Analyzer (VSIX and Console) libraries and tools
optimajet/WorkflowEngine.NET
WorkflowEngine.NET - component that adds workflow in your application. It can be fully integrated into your application, or be in the form of a specific service (such as a web service).
ivanpaulovich/hexagonal-architecture-acerola
An Hexagonal Architecture service template with DDD, CQRS, TDD and SOLID using .NET Core 2.0. All small features are testable and could be mocked. Adapters could be mocked or exchanged.
autofac/Examples
Example projects that consume and demonstrate Autofac IoC functionality and integration
Version Downloads Last updated
7.0.0 182,368 7/13/2024
6.0.0 5,006,740 9/28/2020
5.1.0 649,580 2/19/2020
5.0.0 50,867 1/30/2020
4.1.0 1,708,756 6/21/2018
4.0.1 1,164,035 9/7/2016
4.0.0 70,519 8/9/2016
4.0.0-rc3-289 1,419 6/28/2016
4.0.0-rc2-286 1,090 6/28/2016
4.0.0-rc2-281 1,274 6/9/2016
4.0.0-rc2-274 1,300 6/8/2016
4.0.0-rc1-268 2,803 11/20/2015
4.0.0-beta8-262 1,541 10/22/2015
4.0.0-beta7-252 1,440 9/8/2015
4.0.0-beta6-248 2,201 8/5/2015
3.3.0 1,181,157 7/9/2014
3.2.1 158,630 3/27/2014
3.2.0 51,447 12/17/2013
3.1.0 93,179 7/12/2013