CodeOfChaos.Extensions.DependencyInjection.Generators
0.84.6
Prefix Reserved
See the version list below for details.
dotnet add package CodeOfChaos.Extensions.DependencyInjection.Generators --version 0.84.6
NuGet\Install-Package CodeOfChaos.Extensions.DependencyInjection.Generators -Version 0.84.6
<PackageReference Include="CodeOfChaos.Extensions.DependencyInjection.Generators" Version="0.84.6"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
<PackageVersion Include="CodeOfChaos.Extensions.DependencyInjection.Generators" Version="0.84.6" />
<PackageReference Include="CodeOfChaos.Extensions.DependencyInjection.Generators"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
paket add CodeOfChaos.Extensions.DependencyInjection.Generators --version 0.84.6
#r "nuget: CodeOfChaos.Extensions.DependencyInjection.Generators, 0.84.6"
#:package CodeOfChaos.Extensions.DependencyInjection.Generators@0.84.6
#addin nuget:?package=CodeOfChaos.Extensions.DependencyInjection.Generators&version=0.84.6
#tool nuget:?package=CodeOfChaos.Extensions.DependencyInjection.Generators&version=0.84.6
⛓️💥 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.
Learn more about Target Frameworks and .NET Standard.
This package has no dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.86.0 | 0 | 11/19/2025 |
| 0.85.0 | 59 | 11/17/2025 |
| 0.84.6 | 187 | 11/14/2025 |
| 0.83.2 | 208 | 10/22/2025 |
| 0.83.1 | 197 | 9/12/2025 |
| 0.81.1 | 173 | 9/5/2025 |
| 0.81.0 | 199 | 9/3/2025 |
| 0.80.0 | 127 | 8/23/2025 |
| 0.79.1 | 178 | 8/19/2025 |
| 0.79.0 | 165 | 8/19/2025 |
| 0.77.3 | 122 | 8/15/2025 |
| 0.75.0 | 123 | 8/15/2025 |
| 0.74.0 | 168 | 8/13/2025 |
| 0.73.0 | 173 | 8/13/2025 |
| 0.72.0 | 168 | 8/13/2025 |
| 0.71.0 | 171 | 8/13/2025 |
| 0.70.1 | 360 | 7/20/2025 |
| 0.70.0 | 350 | 7/20/2025 |
| 0.69.0 | 100 | 7/5/2025 |
| 0.68.0 | 328 | 5/19/2025 |
| 0.67.0 | 180 | 5/19/2025 |
| 0.66.1 | 143 | 5/9/2025 |
| 0.66.0 | 178 | 5/5/2025 |
| 0.65.0 | 198 | 4/30/2025 |
| 0.64.0 | 214 | 4/23/2025 |
| 0.63.0 | 215 | 4/23/2025 |
| 0.62.0 | 199 | 4/23/2025 |
| 0.61.0 | 196 | 4/23/2025 |
| 0.60.0 | 201 | 4/18/2025 |
| 0.59.1 | 188 | 4/18/2025 |
| 0.59.0 | 250 | 4/17/2025 |
| 0.58.0 | 225 | 4/17/2025 |
| 0.57.0 | 151 | 4/5/2025 |
| 0.56.0 | 119 | 3/29/2025 |
| 0.55.0 | 184 | 3/26/2025 |
| 0.54.0 | 491 | 3/26/2025 |
| 0.53.0 | 476 | 3/24/2025 |
| 0.52.0 | 443 | 3/24/2025 |
| 0.51.0 | 194 | 3/22/2025 |
| 0.50.0 | 181 | 3/20/2025 |
| 0.49.0 | 181 | 3/20/2025 |
| 0.48.0 | 182 | 3/18/2025 |
| 0.47.0 | 204 | 3/18/2025 |
| 0.46.0 | 176 | 3/18/2025 |
| 0.45.0 | 197 | 3/18/2025 |
| 0.44.0 | 173 | 3/17/2025 |
| 0.43.0 | 150 | 3/14/2025 |
| 0.42.3 | 246 | 3/4/2025 |
| 0.42.3-preview.1 | 197 | 3/4/2025 |
| 0.41.2 | 247 | 3/4/2025 |
| 0.41.1 | 223 | 3/3/2025 |
| 0.41.0 | 144 | 2/26/2025 |
| 0.40.1 | 131 | 2/24/2025 |
| 0.40.0 | 127 | 2/24/2025 |
| 0.39.4 | 157 | 2/20/2025 |
| 0.39.3 | 139 | 2/20/2025 |
| 0.39.2 | 144 | 2/20/2025 |
| 0.39.1 | 142 | 2/20/2025 |
| 0.39.0 | 152 | 2/18/2025 |
| 0.37.2 | 133 | 2/16/2025 |
| 0.37.1 | 156 | 2/16/2025 |
| 0.36.4 | 159 | 2/14/2025 |
| 0.36.0 | 146 | 2/14/2025 |
| 0.35.0 | 159 | 2/8/2025 |
| 0.34.0 | 133 | 2/5/2025 |
| 0.33.0 | 167 | 2/5/2025 |
| 0.32.0 | 149 | 2/1/2025 |
| 0.31.0 | 133 | 1/29/2025 |
| 0.30.0 | 110 | 1/8/2025 |