CodeOfChaos.Extensions.DependencyInjection
0.30.0
Prefix Reserved
See the version list below for details.
dotnet add package CodeOfChaos.Extensions.DependencyInjection --version 0.30.0
NuGet\Install-Package CodeOfChaos.Extensions.DependencyInjection -Version 0.30.0
<PackageReference Include="CodeOfChaos.Extensions.DependencyInjection" Version="0.30.0" />
<PackageVersion Include="CodeOfChaos.Extensions.DependencyInjection" Version="0.30.0" />
<PackageReference Include="CodeOfChaos.Extensions.DependencyInjection" />
paket add CodeOfChaos.Extensions.DependencyInjection --version 0.30.0
#r "nuget: CodeOfChaos.Extensions.DependencyInjection, 0.30.0"
#:package CodeOfChaos.Extensions.DependencyInjection@0.30.0
#addin nuget:?package=CodeOfChaos.Extensions.DependencyInjection&version=0.30.0
#tool nuget:?package=CodeOfChaos.Extensions.DependencyInjection&version=0.30.0
⛓️💥 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 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. |
-
net9.0
- Microsoft.Extensions.DependencyInjection (>= 9.0.0)
- Microsoft.Extensions.ObjectPool (>= 9.0.0)
- System.Buffers (>= 4.6.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 | 264 | 11/24/2025 |
| 0.87.0 | 403 | 11/20/2025 |
| 0.86.0 | 384 | 11/19/2025 |
| 0.85.0 | 352 | 11/17/2025 |
| 0.84.6 | 441 | 11/14/2025 |
| 0.83.2 | 740 | 10/22/2025 |
| 0.83.1 | 405 | 9/12/2025 |
| 0.81.1 | 294 | 9/5/2025 |
| 0.81.0 | 192 | 9/3/2025 |
| 0.80.0 | 137 | 8/23/2025 |
| 0.79.1 | 451 | 8/19/2025 |
| 0.79.0 | 167 | 8/19/2025 |
| 0.77.3 | 144 | 8/15/2025 |
| 0.75.0 | 126 | 8/15/2025 |
| 0.74.0 | 172 | 8/13/2025 |
| 0.73.0 | 181 | 8/13/2025 |
| 0.72.0 | 171 | 8/13/2025 |
| 0.71.0 | 174 | 8/13/2025 |
| 0.70.1 | 1,326 | 7/20/2025 |
| 0.70.0 | 351 | 7/20/2025 |
| 0.69.0 | 137 | 7/5/2025 |
| 0.68.0 | 624 | 5/19/2025 |
| 0.67.0 | 183 | 5/19/2025 |
| 0.66.1 | 152 | 5/9/2025 |
| 0.66.0 | 199 | 5/5/2025 |
| 0.65.0 | 233 | 4/30/2025 |
| 0.64.0 | 227 | 4/23/2025 |
| 0.63.0 | 205 | 4/23/2025 |
| 0.62.0 | 200 | 4/23/2025 |
| 0.61.0 | 204 | 4/23/2025 |
| 0.60.0 | 180 | 4/18/2025 |
| 0.59.1 | 513 | 4/18/2025 |
| 0.59.0 | 311 | 4/17/2025 |
| 0.58.0 | 228 | 4/17/2025 |
| 0.57.0 | 199 | 4/5/2025 |
| 0.56.0 | 140 | 3/29/2025 |
| 0.55.0 | 176 | 3/26/2025 |
| 0.54.0 | 512 | 3/26/2025 |
| 0.53.0 | 454 | 3/24/2025 |
| 0.52.0 | 436 | 3/24/2025 |
| 0.51.0 | 188 | 3/22/2025 |
| 0.50.0 | 193 | 3/20/2025 |
| 0.49.0 | 184 | 3/20/2025 |
| 0.48.0 | 184 | 3/18/2025 |
| 0.47.0 | 180 | 3/18/2025 |
| 0.46.0 | 180 | 3/18/2025 |
| 0.45.0 | 193 | 3/18/2025 |
| 0.44.0 | 182 | 3/17/2025 |
| 0.43.0 | 133 | 3/14/2025 |
| 0.42.3 | 256 | 3/4/2025 |
| 0.42.3-preview.1 | 193 | 3/4/2025 |
| 0.41.2 | 249 | 3/4/2025 |
| 0.41.1 | 229 | 3/3/2025 |
| 0.41.0 | 166 | 2/26/2025 |
| 0.40.1 | 165 | 2/24/2025 |
| 0.40.0 | 137 | 2/24/2025 |
| 0.39.4 | 169 | 2/20/2025 |
| 0.39.3 | 138 | 2/20/2025 |
| 0.39.2 | 148 | 2/20/2025 |
| 0.39.1 | 139 | 2/20/2025 |
| 0.39.0 | 191 | 2/18/2025 |
| 0.37.2 | 196 | 2/16/2025 |
| 0.37.1 | 137 | 2/16/2025 |
| 0.36.4 | 200 | 2/14/2025 |
| 0.36.0 | 141 | 2/14/2025 |
| 0.35.0 | 139 | 2/8/2025 |
| 0.34.0 | 154 | 2/5/2025 |
| 0.33.0 | 135 | 2/5/2025 |
| 0.32.0 | 242 | 2/1/2025 |
| 0.31.0 | 138 | 1/29/2025 |
| 0.30.0 | 139 | 1/8/2025 |
| 0.2.0 | 162 | 10/31/2024 |
| 0.1.1 | 264 | 7/1/2024 |
| 0.1.0 | 238 | 6/7/2024 |