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
<PackageReference Include="Autofac.Configuration" Version="7.0.0" />
paket add Autofac.Configuration --version 7.0.0
#r "nuget: Autofac.Configuration, 7.0.0"
// 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.
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:
- 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
- JSON configuration uses
- Build the configuration using the
Microsoft.Extensions.Configuration.ConfigurationBuilder
. - Create a new
Autofac.Configuration.ConfigurationModule
and pass the builtMicrosoft.Extensions.Configuration.IConfiguration
into it. - 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 | Versions 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. |
-
.NETStandard 2.0
- Autofac (>= 8.0.0)
- Microsoft.Extensions.Configuration (>= 8.0.0)
- Microsoft.Extensions.Configuration.Binder (>= 8.0.2)
-
.NETStandard 2.1
- Autofac (>= 8.0.0)
- Microsoft.Extensions.Configuration (>= 8.0.0)
- Microsoft.Extensions.Configuration.Binder (>= 8.0.2)
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 | 121,492 | 7/13/2024 |
6.0.0 | 4,833,206 | 9/28/2020 |
5.1.0 | 646,405 | 2/19/2020 |
5.0.0 | 50,332 | 1/30/2020 |
4.1.0 | 1,694,355 | 6/21/2018 |
4.0.1 | 1,150,334 | 9/7/2016 |
4.0.0 | 69,718 | 8/9/2016 |
4.0.0-rc3-289 | 1,410 | 6/28/2016 |
4.0.0-rc2-286 | 1,082 | 6/28/2016 |
4.0.0-rc2-281 | 1,265 | 6/9/2016 |
4.0.0-rc2-274 | 1,290 | 6/8/2016 |
4.0.0-rc1-268 | 2,794 | 11/20/2015 |
4.0.0-beta8-262 | 1,532 | 10/22/2015 |
4.0.0-beta7-252 | 1,431 | 9/8/2015 |
4.0.0-beta6-248 | 2,188 | 8/5/2015 |
3.3.0 | 1,169,251 | 7/9/2014 |
3.2.1 | 155,469 | 3/27/2014 |
3.2.0 | 50,985 | 12/17/2013 |
3.1.0 | 92,458 | 7/12/2013 |
Release notes are at https://github.com/autofac/Autofac.Configuration/releases