Roar.DependencyInjection 2.2.0

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

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • 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.