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.
- 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
dotnet add package Roar.DependencyInjectionSimply annotate your classes with a lifetime attribute:
using Roar.DependencyInjection;
[ScopedService]
public class OrderService
{
}Roar automatically generates:
builder.Services.AddScoped<OrderService>();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>();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.
Once your services are annotated, a single call wires everything:
builder.Services.AddRoarServices();No more manual registrations.
Expose gRPC services using the same simple approach:
[GrpcService]
public class OrderGrpcService : OrderServiceContract.OrderServiceContractBase
{
}Roar generates:
app.MapGrpcService<OrderGrpcService>();app.MapRoarEndpoints();All discovered gRPC services are mapped automatically.
| 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 |
- 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.
MIT