Nemza.AutoDI
1.0.0
dotnet add package Nemza.AutoDI --version 1.0.0
NuGet\Install-Package Nemza.AutoDI -Version 1.0.0
<PackageReference Include="Nemza.AutoDI" Version="1.0.0" />
<PackageVersion Include="Nemza.AutoDI" Version="1.0.0" />
<PackageReference Include="Nemza.AutoDI" />
paket add Nemza.AutoDI --version 1.0.0
#r "nuget: Nemza.AutoDI, 1.0.0"
#:package Nemza.AutoDI@1.0.0
#addin nuget:?package=Nemza.AutoDI&version=1.0.0
#tool nuget:?package=Nemza.AutoDI&version=1.0.0
AutoDI
Compile-time dependency injection registration for .NET. No runtime reflection, no assembly scanning — services are discovered and registered at compile time via a Roslyn source generator.
Why AutoDI?
Most DI registration libraries (like Scrutor) scan assemblies at runtime using reflection. This has two costs:
- Startup latency — reflection is slow, especially with large assemblies
- AOT incompatibility — reflection-based scanning breaks Native AOT publishing
AutoDI solves both by moving service discovery to compile time.
Installation
dotnet add package AutoDI
Usage
Decorate your service classes with one of three attributes:
using AutoDI;
[RegisterScoped]
public class UserService : IUserService { }
[RegisterSingleton]
public class ConfigService : IConfigService { }
[RegisterTransient]
public class EmailSender : IEmailSender { }
Then call the generated extension method in your startup code:
builder.Services.AddAutoRegisteredServices();
That's it. No manual registration, no assembly scanning, no reflection.
Supported Patterns
// Multiple interfaces
[RegisterScoped]
public class FooBarService : IFoo, IBar { }
// → AddScoped<IFoo, FooBarService>()
// → AddScoped<IBar, FooBarService>()
// Open generics
[RegisterScoped]
public class Repository<T> : IRepository<T> { }
// → AddScoped(typeof(IRepository<>), typeof(Repository<>))
// Self-registration (no interface)
[RegisterScoped]
public class StandaloneService { }
// → AddScoped<StandaloneService>()
// Internal classes
[RegisterScoped]
internal sealed class InternalService : IInternalService { }
// → AddScoped<IInternalService, InternalService>()
IDisposable is automatically excluded from interface registrations.
Benchmark
Measured on .NET 10, 50 services, BenchmarkDotNet.
| Method | Mean | Allocated |
|---|---|---|
| Manual registration | 2.1 μs | 4.2 KB |
| AutoDI (compile-time) | 2.3 μs | 4.2 KB |
| Scrutor assembly scan | 812.4 μs | 128.7 KB |
AutoDI is effectively identical to manual registration because it is manual registration — just written by the compiler instead of you.
Benchmark figures are placeholders — replace with actual BenchmarkDotNet output from P7.
Native AOT
AutoDI is fully compatible with Native AOT. Because all registration code is generated at compile time, there is no reflection at startup:
<PropertyGroup>
<PublishAot>true</PublishAot>
</PropertyGroup>
dotnet publish -c Release -r linux-x64 --self-contained
No trim warnings. No reflection. Just fast startup.
How It Works
AutoDI uses a Roslyn IIncrementalGenerator to scan your project at compile time. It finds every class decorated with [RegisterScoped], [RegisterSingleton], or [RegisterTransient] and emits a static extension method:
// AutoDI.g.cs — generated at compile time
public static partial class AutoDIServiceCollectionExtensions
{
public static IServiceCollection AddAutoRegisteredServices(
this IServiceCollection services)
{
services.AddScoped<IUserService, UserService>();
services.AddSingleton<IConfigService, ConfigService>();
services.AddTransient<IEmailSender, EmailSender>();
return services;
}
}
The generated file is visible in your IDE under Dependencies → Analyzers → AutoDI.SourceGenerator.
License
MIT
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. 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 was computed. 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 was computed. 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. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.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 |
|---|---|---|
| 1.0.0 | 126 | 6/1/2026 |
| 0.0.0-preview.19 | 57 | 5/29/2026 |
| 0.0.0-preview.18 | 61 | 5/29/2026 |