Roar.DependencyInjection
2.2.0
dotnet add package Roar.DependencyInjection --version 2.2.0
NuGet\Install-Package Roar.DependencyInjection -Version 2.2.0
<PackageReference Include="Roar.DependencyInjection" Version="2.2.0" />
<PackageVersion Include="Roar.DependencyInjection" Version="2.2.0" />
<PackageReference Include="Roar.DependencyInjection" />
paket add Roar.DependencyInjection --version 2.2.0
#r "nuget: Roar.DependencyInjection, 2.2.0"
#:package Roar.DependencyInjection@2.2.0
#addin nuget:?package=Roar.DependencyInjection&version=2.2.0
#tool nuget:?package=Roar.DependencyInjection&version=2.2.0
Roar.DependencyInjection
Compile-time dependency injection made simple.
Roar.DependencyInjection removes the need for repetitive service registration code by generating it at compile time. Instead of maintaining long lists of AddScoped, AddSingleton, AddTransient, AddHostedService, and MapGrpcService calls, you declare intent through attributes�and Roar wires everything automatically.
No reflection. No runtime scanning. Just clean, deterministic, generated code.
Features
- Automatic convention-based service registration
- Compile-time source generation (AOT and trimming safe)
- Clear, attribute-driven service roles
- Deterministic and predictable wiring
- Zero-reflection runtime behavior
- Seamless integration with ASP.NET Core and gRPC
Installation
dotnet add package Roar.DependencyInjection
Basic usage
Mark services by role
Simply annotate your classes with a lifetime attribute:
using Roar.DependencyInjection;
[ScopedService]
public class OrderService
{
}
Roar automatically generates:
builder.Services.AddScoped<OrderService>();
Explicit interface mapping
Want to register a service under a specific interface? Just declare it:
[ScopedService]
[AsService(typeof(IOrderService))]
public class OrderService : IOrderService
{
}
Generated result:
builder.Services.AddScoped<IOrderService, OrderService>();
Mapping to multiple interfaces
Roar supports multiple service contracts out of the box:
[ScopedService]
[AsService(typeof(IFoo))]
[AsService(typeof(IBar))]
public class MyService : IFoo, IBar
{
}
Generated:
builder.Services.AddScoped<IFoo, MyService>();
builder.Services.AddScoped<IBar, MyService>();
All mappings are validated at compile time to ensure correctness.
Register all services
Once your services are annotated, a single call wires everything:
builder.Services.AddRoarServices();
No more manual registrations.
gRPC endpoints
Expose gRPC services using the same simple approach:
[GrpcService]
public class OrderGrpcService : OrderServiceContract.OrderServiceContractBase
{
}
Roar generates:
app.MapGrpcService<OrderGrpcService>();
Map all endpoints
app.MapRoarEndpoints();
All discovered gRPC services are mapped automatically.
Service roles
| Attribute | Purpose |
|---|---|
ScopedService |
Register as Scoped service |
SingletonService |
Register as Singleton service |
TransientService |
Register as Transient service |
BackgroundWorker |
Register as hosted background service |
GrpcService |
Register as gRPC endpoint |
Why Roar?
- Less boilerplate
- Fewer DI mistakes
- Cleaner Program.cs
- Compile-time validation
- Safe for AOT, trimming, and native compilation
Roar lets you focus on architecture instead of wiring.
License
MIT
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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. |
-
net10.0
- 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 |
|---|---|---|
| 2.2.0 | 180 | 1/25/2026 |
| 2.0.0 | 118 | 1/19/2026 |
| 1.0.1 | 115 | 1/16/2026 |
| 1.0.0 | 123 | 1/16/2026 |
| 1.0.0-preview.4 | 71 | 1/10/2026 |
| 1.0.0-preview.3 | 67 | 1/10/2026 |
| 1.0.0-preview.2 | 74 | 1/10/2026 |
| 1.0.0-preview.1 | 72 | 1/10/2026 |
- Hotfix error when using with Blazor WebAssembly Standalone projects.