CodeOfChaos.Extensions.DependencyInjection
0.87.2
Prefix Reserved
dotnet add package CodeOfChaos.Extensions.DependencyInjection --version 0.87.2
NuGet\Install-Package CodeOfChaos.Extensions.DependencyInjection -Version 0.87.2
<PackageReference Include="CodeOfChaos.Extensions.DependencyInjection" Version="0.87.2" />
<PackageVersion Include="CodeOfChaos.Extensions.DependencyInjection" Version="0.87.2" />
<PackageReference Include="CodeOfChaos.Extensions.DependencyInjection" />
paket add CodeOfChaos.Extensions.DependencyInjection --version 0.87.2
#r "nuget: CodeOfChaos.Extensions.DependencyInjection, 0.87.2"
#:package CodeOfChaos.Extensions.DependencyInjection@0.87.2
#addin nuget:?package=CodeOfChaos.Extensions.DependencyInjection&version=0.87.2
#tool nuget:?package=CodeOfChaos.Extensions.DependencyInjection&version=0.87.2
⛓️💥 CodeOfChaos.Extensions.DependencyInjection ⛓️💥
CodeOfChaos.Extensions.DependencyInjection is a library that provides tools for automizing dependency injection in .NET projects. It includes source generators for automatic registration of services and attributes to facilitate DI.
Features
- Automatic Service Registration: Use source generators to automatically register services in your project.
- Custom Attributes: Define custom attributes to specify the lifetime and other details for your services.
Getting Started
Prerequisites
- .NET 9.0 or later
Installation
You can install CodeOfChaos.Extensions.DependencyInjection via NuGet Package Manager:
dotnet add package CodeOfChaos.Extensions.DependencyInjection
You can install CodeOfChaos.Extensions.DependencyInjection.Generator via NuGet Package Manager:
dotnet add package CodeOfChaos.Extensions.DependencyInjection.Generator
Usage
Define Services with Attributes
You can use the provided attributes to define services:
InjectableService: Simple attribute to register a class to the implementation which is inserted as a type generic.public interface IExampleService; [InjectableService<IExampleService>(ServiceLifetime.Singleton)] public class ExampleService : IExampleService { // ... }FactoryCreatedService: Marks the class as a service which creation depends on another injected service.- The factory service must implement
IFactoryService<>
public interface ICreatedService; [FactoryCreatedService<IExampleFactory, ICreatedService>(ServiceLifetime.Transient)] public class CreatedService : ICreatedService; // The above service is something that is created by the Factory service [InjectableService<IExampleFactory>(ServiceLifetime.Singleton)] public class ExampleFactory : IExampleFactory { public ICreatedService Create() => new CreatedService(); } public interface IExampleFactory : IFactoryService<ICreatedService>;- The factory service must implement
PooledInjectableService: Marks the class as a poolable service. This library creates a classAutoPoolableServiceunder which the class will be registered.- It uses
PooledInjectableServiceObjectPolicyto create a policy. - The poolable service must implement
PooledInjectableServiceObjectPolicy
public interface IExamplePooled : IManualPoolable; [PooledInjectableService<IExamplePooled, ExamplePooled>] public class ExamplePooled : IExamplePooled { public bool Reset() => true; }- It uses
Generate Service Registrations
The source generator will automatically create the necessary registration code. C
all the generated registration method in your Startup or Program class:
using Microsoft.Extensions.DependencyInjection;
var services = new ServiceCollection();
services.RegisterServicesFromYourAssemblyName();
Contributing
Contributions are welcome! Please fork this repository and submit a pull request.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net9.0 is compatible. 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 is compatible. 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. |
-
net10.0
- JetBrains.Annotations (>= 2025.2.2)
- Microsoft.Extensions.DependencyInjection (>= 10.0.0)
- Microsoft.Extensions.ObjectPool (>= 10.0.0)
-
net9.0
- JetBrains.Annotations (>= 2025.2.2)
- Microsoft.Extensions.DependencyInjection (>= 10.0.0)
- Microsoft.Extensions.ObjectPool (>= 10.0.0)
NuGet packages (10)
Showing the top 5 NuGet packages that depend on CodeOfChaos.Extensions.DependencyInjection:
| Package | Downloads |
|---|---|
|
InfiniLore.InfiniBlazor
InfiniLore's Component Library |
|
|
InfiniLore.Lucide
Use Lucide in your Blazor apps |
|
|
InfiniLore.InfiniBlazor.Core.Components
InfiniLore's Component Library |
|
|
InfiniLore.InfiniBlazor.Core.Theming
InfiniLore's Component Library |
|
|
InfiniLore.InfiniBlazor.Core.Toasting
InfiniLore's Component Library |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.87.2 | 1,711 | 11/24/2025 |
| 0.87.0 | 429 | 11/20/2025 |
| 0.86.0 | 404 | 11/19/2025 |
| 0.85.0 | 380 | 11/17/2025 |
| 0.84.6 | 655 | 11/14/2025 |
| 0.83.2 | 1,011 | 10/22/2025 |
| 0.83.1 | 432 | 9/12/2025 |
| 0.81.1 | 328 | 9/5/2025 |
| 0.81.0 | 211 | 9/3/2025 |
| 0.80.0 | 158 | 8/23/2025 |
| 0.79.1 | 479 | 8/19/2025 |
| 0.79.0 | 188 | 8/19/2025 |
| 0.77.3 | 173 | 8/15/2025 |
| 0.75.0 | 148 | 8/15/2025 |
| 0.74.0 | 192 | 8/13/2025 |
| 0.73.0 | 204 | 8/13/2025 |
| 0.72.0 | 188 | 8/13/2025 |
| 0.71.0 | 197 | 8/13/2025 |
| 0.70.1 | 1,343 | 7/20/2025 |
| 0.70.0 | 371 | 7/20/2025 |