DynamicDI 3.0.1
dotnet add package DynamicDI --version 3.0.1
NuGet\Install-Package DynamicDI -Version 3.0.1
<PackageReference Include="DynamicDI" Version="3.0.1" />
<PackageVersion Include="DynamicDI" Version="3.0.1" />
<PackageReference Include="DynamicDI" />
paket add DynamicDI --version 3.0.1
#r "nuget: DynamicDI, 3.0.1"
#:package DynamicDI@3.0.1
#addin nuget:?package=DynamicDI&version=3.0.1
#tool nuget:?package=DynamicDI&version=3.0.1
Dynamic DI Registration Library
Overview
This library provides automatic service registration in the ASP.NET Core Dependency Injection container by scanning assemblies and detecting classes marked with a [Service] attribute.
It simplifies and streamlines the process of service registration, reducing manual configurations and improving maintainability.
Features
✔ Automatic Registration – Detects and registers services dynamically based on attributes.
✔ Flexible Interface Binding – Allows you to register the specified interfaces, or register all of them.
✔ Configurable Lifetimes – Allows specifying service lifetimes (Transient, Scoped, Singleton).
✔ Assembly Scanning – Automatically discovers and registers services from all project assemblies.
✔ Zero Boilerplate Code – Eliminates the need for manual AddTransient, AddScoped, or AddSingleton calls.
Installation
Install via NuGet Package Manager:
Install-Package DynamicDI
Or using .NET CLI:
dotnet add package DynamicDI
Usage
1. Mark Services with the ServiceAttribute
Apply the [Service] attribute to classes:
[Service([typeof(ITestService)])]
public class TestService(ITestRepository repository) : ITestService, ITestable
{
private readonly ITestRepository _repository = repository;
public async Task<IEnumerable<CriticalSituationImage>> GetCsiAsync(CancellationToken cancellationToken = default)
{
return await _repository.GetCsiAsync(cancellationToken);
}
public string GetHelloMessage() => "Hello World!";
public List<string> GetMessages() => _repository.GetMessages();
public bool IsThisATest() => true;
}
[Service]
public class TestRepository : ITestRepository
{
private readonly DataContext _dbContext;
public TestRepository(DataContext dataContext)
{
_dbContext = dataContext;
}
public async Task<IEnumerable<CriticalSituationImage>> GetCsiAsync(CancellationToken cancellationToken = default)
{
return await _dbContext.CriticalSituationImages.AsNoTracking().ToListAsync(cancellationToken);
}
public List<string> GetMessages()
{
return [ "Hello", "World", "!" ];
}
}
[Service([typeof(DataContext)])]
public class DataContext : DbContext
{
}
2. Register Services
Modify the Program.cs file to call the builder.Services.RegisterServices() extension method:
using DynamicDI;
var builder = WebApplication.CreateBuilder(args);
builder.Services.RegisterServices(); // services registration
You can also specify the assemblies from where you want to register services:
using DynamicDI;
Assembly[] assemblies = GetAssemblies(); // your assemblies
builder.Services.RegisterServices(assemblies);
3. Inject Services Anywhere
Once registered, services can be injected as usual:
public class MyController : ControllerBase
{
private readonly IUserService _userService;
public MyController(IUserService userService)
{
_userService = userService;
}
}
License
This library is open-source and licensed under the MIT License. Contributions and feedback are welcome! 🚀
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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 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. |
-
net7.0
- Microsoft.EntityFrameworkCore (>= 7.0.20)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 7.0.0)
- Microsoft.Extensions.DependencyModel (>= 7.0.0)
-
net8.0
- Microsoft.EntityFrameworkCore (>= 7.0.20)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 7.0.0)
- Microsoft.Extensions.DependencyModel (>= 7.0.0)
-
net9.0
- Microsoft.EntityFrameworkCore (>= 7.0.20)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 7.0.0)
- Microsoft.Extensions.DependencyModel (>= 7.0.0)
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 |
|---|---|---|
| 3.0.1 | 211 | 10/9/2025 |
one ServiceAttribute attribute for all cases