Cogito.Autofac
6.1.4
dotnet add package Cogito.Autofac --version 6.1.4
NuGet\Install-Package Cogito.Autofac -Version 6.1.4
<PackageReference Include="Cogito.Autofac" Version="6.1.4" />
<PackageVersion Include="Cogito.Autofac" Version="6.1.4" />
<PackageReference Include="Cogito.Autofac" />
paket add Cogito.Autofac --version 6.1.4
#r "nuget: Cogito.Autofac, 6.1.4"
#:package Cogito.Autofac@6.1.4
#addin nuget:?package=Cogito.Autofac&version=6.1.4
#tool nuget:?package=Cogito.Autofac&version=6.1.4
Cogito.Autofac
Attribute-driven registration for Autofac, plus a convention for composing an application out of assemblies rather than a central wiring file.
Why
Autofac's fluent API puts every registration in one place, far from the type it registers. As an application grows that file becomes the thing everyone edits and nobody owns. This package lets a type declare how it is registered, and lets each assembly contribute its own module, so composition follows the code.
Install
dotnet add package Cogito.Autofac
Registering by attribute
Mark a type with [RegisterAs] and whatever lifetime and modifier attributes apply, then scan for them:
[RegisterAs(typeof(IGreeter))]
[RegisterSingleInstance]
public class Greeter : IGreeter
{
public string Greet(string name) => $"Hello, {name}.";
}
var builder = new ContainerBuilder();
builder.RegisterFromAttributes(typeof(Greeter).Assembly);
var container = builder.Build();
The attributes cover the registration options you would otherwise write fluently — among them
RegisterAs, RegisterType, RegisterSingleInstance, RegisterInstancePerLifetimeScope,
RegisterNamed, RegisterKeyed, RegisterExternallyOwned, RegisterOrder, RegisterPriority,
RegisterAggregateService and RegisterWithAttributeFiltering.
For registrations that cannot be expressed declaratively, implement IRegistrationBuilderAttribute or
IRegistrationRootAttribute and the scanner will call your code.
Composing across assemblies
Derive from ModuleBase in each assembly that has something to contribute:
public class AssemblyModule : ModuleBase
{
protected override void Register(ContainerBuilder builder)
{
builder.RegisterFromAttributes(typeof(AssemblyModule).Assembly);
}
}
and load every one of them that the dependency context can see:
builder.RegisterAllAssemblyModules();
Each module is registered once no matter how many times it is reached, so modules can safely depend on each other.
Also here
OrderedRegistrationExtensions/OrderedResolutionExtensions— resolve a set of services in a declared order rather than registration order.LifetimeScopeContext— flow the current lifetime scope through a logical call context.ComponentContextExtensions,ContainerBuilderExtensions— smaller helpers over the Autofac API.
License
MIT.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 is compatible. 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.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 is compatible. 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. |
-
.NETFramework 4.7.2
- Autofac (>= 9.3.2)
- Autofac.Extras.AggregateService (>= 7.0.1)
- Castle.Core (>= 5.2.1)
- Microsoft.Extensions.DependencyModel (>= 10.0.12)
-
.NETStandard 2.0
- Autofac (>= 9.3.2)
- Autofac.Extras.AggregateService (>= 7.0.1)
- Castle.Core (>= 5.2.1)
- Microsoft.Extensions.DependencyModel (>= 10.0.12)
- System.Runtime.Loader (>= 4.3.0)
-
net6.0
- Autofac (>= 9.3.2)
- Autofac.Extras.AggregateService (>= 7.0.1)
- Castle.Core (>= 5.2.1)
- Microsoft.Extensions.DependencyModel (>= 10.0.12)
NuGet packages (16)
Showing the top 5 NuGet packages that depend on Cogito.Autofac:
| Package | Downloads |
|---|---|
|
Cogito.Autofac.DependencyInjection
Provides various Autofac related integration to Microsoft.Extensions.DependencyInjection. |
|
|
Cogito.Extensions.Logging.Autofac
Makes Microsoft.Extensions.Logging objects available to the Autofac container. |
|
|
Cogito.Serilog.Autofac
Autofac extension for Serilog. |
|
|
Cogito.MassTransit.Autofac
Alternative Autofac integration for MassTransit. |
|
|
Cogito.Extensions.Configuration.Autofac
Extensions for Microsoft.Extensions.Configuration. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 6.1.4 | 73 | 11/28/2026 |
| 6.1.3 | 1,564 | 9/14/2026 |
| 6.1.2 | 796 | 9/10/2026 |
| 6.1.1 | 985 | 9/10/2026 |
| 6.1.0 | 5,902 | 1/7/2025 |
| 6.0.0 | 8,589 | 12/20/2024 |
| 5.0.5 | 3,147 | 11/29/2023 |
| 5.0.4 | 3,750 | 11/29/2023 |
| 5.0.0 | 1,842 | 11/7/2023 |
| 4.0.18 | 320 | 11/7/2023 |
| 4.0.13 | 8,278 | 9/4/2022 |
| 4.0.11 | 844 | 9/4/2022 |
| 4.0.10 | 957 | 6/6/2022 |
| 4.0.9 | 986 | 6/6/2022 |
| 4.0.7 | 898 | 6/5/2022 |
| 4.0.6 | 912 | 6/5/2022 |
| 4.0.4 | 865 | 6/5/2022 |
| 3.1.10 | 895 | 6/5/2022 |
| 3.1.9 | 3,610 | 10/18/2021 |
| 3.1.7 | 16,578 | 10/10/2021 |