IL.AttributeBasedDI
1.3.2
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package IL.AttributeBasedDI --version 1.3.2
NuGet\Install-Package IL.AttributeBasedDI -Version 1.3.2
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="IL.AttributeBasedDI" Version="1.3.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="IL.AttributeBasedDI" Version="1.3.2" />
<PackageReference Include="IL.AttributeBasedDI" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add IL.AttributeBasedDI --version 1.3.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: IL.AttributeBasedDI, 1.3.2"
#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.
#:package IL.AttributeBasedDI@1.3.2
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=IL.AttributeBasedDI&version=1.3.2
#tool nuget:?package=IL.AttributeBasedDI&version=1.3.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
IL.AttributeBasedDI
Control dependencies and decorators via custom attributes - extends Microsoft.Extensions.DependencyInjection
How to use
- Simply reference IL.AttributeBasedDI in your project
- Use registration extensions coming with library to activate functionality:
(IServiceCollection)services.AddServiceAttributeBasedDependencyInjection()or(WebApplicationBuilder)builder.AddServiceAttributeBasedDependencyInjection()- Allows to filter assemblies reflection search with optional parameter
assemblyFilters("MyProject.*" for example)
- Allows to filter assemblies reflection search with optional parameter
- Use
[Service]attribute for your classes with optional params for auto registration in DI container:- Lifetime - to define current service registration lifetime
- ServiceType - Specifies which service is target for DI registration. If left null/default service will be automatically retrieved either from first interface current class implements or the class itself will become a serviceType.
- Use
[Decorator]attribute for your classes with optional params for auto registration of decorator for specific service type in DI container:- ServiceType - Specifies which service is target for decoration. If left null/default service will be automatically resolved to first interface current class implements.
- DecorationOrder - Defines order of decoration. Lower decoration order will be closer to original implementation in chain of execution order. And, respectively, decorator with highest DecorationOrder will be executed last.
- Keyed Services and Decorators support! If you are using .NET 8 or higher it's possible to assign Keys to your services via corresponding attributes
Examples
IService resolves to:
- DecoratorA
- wrapping a SampleService
[Service]
class SampleService : IService {}
[Decorator]
class DecoratorA : IService {}
IService resolves to:
- DecoratorB
- wrapping a DecoratorA
- wrapping a SampleService
- wrapping a DecoratorA
[Service(serviceType: typeof(IService), lifetime: Lifetime.Singleton)]
class SampleService : IService {}
[Decorator(serviceType: typeof(IService), decorationOrder: 1)]
class DecoratorA : IService
{
public DecoratorA(IService service)
{
//IService service here is actually sample service
}
}
[Decorator(serviceType: typeof(IService), decorationOrder: 2)]
class DecoratorB : IService
{
public DecoratorB(IService service)
{
//IService service here is actually decoratorA
}
}
.NET 8 Examples
[FromKeyedServices("randomKey")] resolves to:
- SampleServiceDefault
[FromKeyedServices("testKey")] resolves to:
- DecoratorA
- wrapping a SampleService
[Service(Key="randomKey")]
class SampleServiceDefault : IService {}
[Service(Key="testKey")]
class SampleService : IService {}
[Decorator(Key="testKey")]
class DecoratorA : IService {}
public class Test([FromKeyedServices("randomKey")] IService randomSvc, [FromKeyedServices("testKey")] IService svc);
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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 is compatible. 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 is compatible. 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net6.0
- IL.Misc (>= 1.1.1)
- Microsoft.Extensions.DependencyInjection (>= 6.0.0)
- Microsoft.Extensions.Options (>= 6.0.0)
-
net7.0
- IL.Misc (>= 1.1.1)
- Microsoft.Extensions.DependencyInjection (>= 7.0.0)
- Microsoft.Extensions.Options (>= 7.0.1)
-
net8.0
- IL.Misc (>= 1.1.1)
- Microsoft.Extensions.DependencyInjection (>= 8.0.0)
- Microsoft.Extensions.Options (>= 8.0.2)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on IL.AttributeBasedDI:
| Package | Downloads |
|---|---|
|
IL.UmbracoSearch
A comprehensive search solution for Umbraco, supporting both Lucene and Azure Search, with extensible indexing and flexible search parameters. |
|
|
IL.AttributeBasedDI.Visualizer
Extension for IL.AttributeBasedDI |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 2.6.1 | 318 | 11/7/2025 |
| 2.6.0 | 529 | 10/30/2025 |
| 2.5.3 | 1,222 | 7/30/2025 |
| 2.5.2 | 917 | 6/10/2025 |
| 2.5.1 | 151 | 5/31/2025 |
| 2.5.0 | 314 | 5/20/2025 |
| 2.4.5 | 300 | 5/7/2025 |
| 2.4.4 | 218 | 5/7/2025 |
| 2.4.3 | 208 | 5/6/2025 |
| 2.4.2 | 201 | 5/6/2025 |
| 2.4.1 | 209 | 5/6/2025 |
| 2.4.0 | 216 | 5/6/2025 |
| 2.3.3 | 212 | 5/5/2025 |
| 2.3.2 | 235 | 4/21/2025 |
| 2.3.1 | 208 | 4/21/2025 |
| 2.3.0 | 207 | 4/21/2025 |
| 2.2.2 | 273 | 4/8/2025 |
| 2.2.1 | 250 | 3/27/2025 |
| 2.2.0 | 311 | 3/17/2025 |
| 2.1.0 | 414 | 2/26/2025 |
| 2.0.2 | 176 | 2/26/2025 |
| 2.0.1 | 164 | 2/26/2025 |
| 2.0.0 | 153 | 2/25/2025 |
| 1.7.0 | 145 | 2/25/2025 |
| 1.6.0 | 1,685 | 9/27/2024 |
| 1.5.1 | 696 | 9/12/2024 |
| 1.5.0 | 267 | 9/5/2024 |
| 1.4.0 | 173 | 9/1/2024 |
| 1.3.2 | 354 | 7/17/2024 |
| 1.3.0 | 427 | 5/6/2024 |
| 1.2.0 | 410 | 3/3/2024 |
| 1.1.3 | 196 | 3/3/2024 |
| 1.0.3 | 545 | 2/22/2024 |
| 1.0.2 | 1,843 | 7/31/2023 |
| 1.0.1 | 245 | 7/29/2023 |
| 1.0.0 | 282 | 7/17/2023 |