DynamicDI 3.1.0

dotnet add package DynamicDI --version 3.1.0
                    
NuGet\Install-Package DynamicDI -Version 3.1.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="DynamicDI" Version="3.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DynamicDI" Version="3.1.0" />
                    
Directory.Packages.props
<PackageReference Include="DynamicDI" />
                    
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 DynamicDI --version 3.1.0
                    
#r "nuget: DynamicDI, 3.1.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 DynamicDI@3.1.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=DynamicDI&version=3.1.0
                    
Install as a Cake Addin
#tool nuget:?package=DynamicDI&version=3.1.0
                    
Install as a Cake Tool

DynamicDI

Attribute-based automatic service registration for Microsoft.Extensions.DependencyInjection.

Overview

DynamicDI scans assemblies for classes decorated with [Service] and registers them in an IServiceCollection. Service lifetime and service types can be configured through the attribute. If service types are not specified, the library uses the interfaces implemented by the class. If the class implements no interfaces, the concrete class type is registered.

Installation

dotnet add package DynamicDI

The library targets Microsoft.Extensions.DependencyInjection and uses Microsoft.Extensions.DependencyModel for project assembly discovery.

Usage

Basic registration

Mark a class with [Service]:

using DynamicDI;

[Service]
public class EmailSender : IEmailSender
{
}

Register services during application startup:

using DynamicDI;

services.RegisterServices();

The parameterless overload scans project assemblies discovered through DependencyContext.Default. To scan specific assemblies, use the overload that accepts assemblies:

services.RegisterServices(typeof(Program).Assembly);

Specifying lifetime

The default lifetime is Transient. Use the ServiceLifetime constructor to override it:

[Service(ServiceLifetime.Singleton)]
public class CacheService : ICacheService
{
}

Supported lifetimes: Transient, Scoped, Singleton.

Specifying service types

By default, all interfaces implemented by the class are used as service types. To register the class for specific service types, pass them to the attribute:

[Service(typeof(IEmailSender), typeof(INotificationSender))]
public class EmailSender : IEmailSender, INotificationSender
{
}

Lifetime and service types can be combined:

[Service(ServiceLifetime.Scoped, typeof(IOrderService))]
public class OrderService : IOrderService
{
}

Important

ImplementedInterfaces includes interfaces inherited from base classes. If the decorated class derives from a base class that implements interfaces you do not want to expose as services for the decorated class, you must pass the decorated class type explicitly to the ServiceAttribute constructor. Otherwise, the library will register the class for every inherited interface.

This applies, for example, to classes derived from DbContext, which implements several infrastructure interfaces (such as IInfrastructure<IServiceProvider>, IDbContextDependencies, IDbContextPoolable, and others) that should not normally be registered in DI.

To register such a class as the concrete type only, specify its own type:

[Service(ServiceLifetime.Scoped, typeof(DataContext))]
public class DataContext : DbContext
{
}

Without typeof(DataContext), the library would infer all interfaces implemented by DbContext and register DataContext for each of them.

If you need to register the class for a subset of interfaces, list only those interfaces:

[Service(ServiceLifetime.Scoped, typeof(IMyRepository), typeof(IUnitOfWork))]
public class MyRepository : BaseRepository, IMyRepository, IUnitOfWork
{
}
Product Compatible and additional computed target framework versions.
.NET 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.1.0 47 10/19/2026
3.0.2 2,575 11/17/2025
3.0.1 290 10/9/2025