CodeOfChaos.Extensions.DependencyInjection 0.81.0

Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package CodeOfChaos.Extensions.DependencyInjection --version 0.81.0
                    
NuGet\Install-Package CodeOfChaos.Extensions.DependencyInjection -Version 0.81.0
                    
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="CodeOfChaos.Extensions.DependencyInjection" Version="0.81.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CodeOfChaos.Extensions.DependencyInjection" Version="0.81.0" />
                    
Directory.Packages.props
<PackageReference Include="CodeOfChaos.Extensions.DependencyInjection" />
                    
Project file
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 CodeOfChaos.Extensions.DependencyInjection --version 0.81.0
                    
#r "nuget: CodeOfChaos.Extensions.DependencyInjection, 0.81.0"
                    
#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 CodeOfChaos.Extensions.DependencyInjection@0.81.0
                    
#: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=CodeOfChaos.Extensions.DependencyInjection&version=0.81.0
                    
Install as a Cake Addin
#tool nuget:?package=CodeOfChaos.Extensions.DependencyInjection&version=0.81.0
                    
Install as a Cake Tool

⛓️‍💥 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>;
    
  • PooledInjectableService : Marks the class as a poolable service. This library creates a class AutoPoolableService under which the class will be registered.

    • It uses PooledInjectableServiceObjectPolicy to create a policy.
    • The poolable service must implement PooledInjectableServiceObjectPolicy
    public interface IExamplePooled : IManualPoolable; 
    
    [PooledInjectableService<IExamplePooled, ExamplePooled>]
    public class ExamplePooled : IExamplePooled {
        public bool Reset() => true;
    }
    
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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (9)

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.Markdown

InfiniLore's Component Library

InfiniLore.InfiniBlazor.Core.Theming

InfiniLore's Component Library

InfiniLore.InfiniBlazor.Extensions.AutoDocumentation

InfiniLore's Component Library

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.83.1 115 9/12/2025
0.81.1 223 9/5/2025
0.81.0 152 9/3/2025
0.80.0 96 8/23/2025
0.79.1 305 8/19/2025
0.79.0 126 8/19/2025
0.77.3 89 8/15/2025
0.75.0 85 8/15/2025
0.74.0 132 8/13/2025
0.73.0 136 8/13/2025
0.72.0 134 8/13/2025
0.71.0 131 8/13/2025
0.70.1 929 7/20/2025
0.70.0 319 7/20/2025
0.69.0 102 7/5/2025
0.68.0 540 5/19/2025
0.67.0 157 5/19/2025
0.66.1 124 5/9/2025
0.66.0 162 5/5/2025
0.65.0 202 4/30/2025
0.64.0 202 4/23/2025
0.63.0 175 4/23/2025
0.62.0 175 4/23/2025
0.61.0 177 4/23/2025
0.60.0 152 4/18/2025
0.59.1 459 4/18/2025
0.59.0 254 4/17/2025
0.58.0 201 4/17/2025
0.57.0 152 4/5/2025
0.56.0 111 3/29/2025
0.55.0 150 3/26/2025
0.54.0 484 3/26/2025
0.53.0 427 3/24/2025
0.52.0 409 3/24/2025
0.51.0 162 3/22/2025
0.50.0 157 3/20/2025
0.49.0 157 3/20/2025
0.48.0 158 3/18/2025
0.47.0 153 3/18/2025
0.46.0 152 3/18/2025
0.45.0 155 3/18/2025
0.44.0 156 3/17/2025
0.43.0 105 3/14/2025
0.42.3 226 3/4/2025
0.42.3-preview.1 188 3/4/2025
0.41.2 221 3/4/2025
0.41.1 200 3/3/2025
0.41.0 126 2/26/2025
0.40.1 130 2/24/2025
0.40.0 108 2/24/2025
0.39.4 135 2/20/2025
0.39.3 112 2/20/2025
0.39.2 114 2/20/2025
0.39.1 108 2/20/2025
0.39.0 145 2/18/2025
0.37.2 153 2/16/2025
0.37.1 109 2/16/2025
0.36.4 153 2/14/2025
0.36.0 117 2/14/2025
0.35.0 113 2/8/2025
0.34.0 123 2/5/2025
0.33.0 110 2/5/2025
0.32.0 179 2/1/2025
0.31.0 113 1/29/2025
0.30.0 111 1/8/2025
0.2.0 133 10/31/2024
0.1.1 233 7/1/2024
0.1.0 215 6/7/2024