Skip to main content

GenDI

Attribute-first Dependency Injection source generation for NativeAOT-ready .NET applications

CI/CD PipelineDeploy DocumentationNuGet GenDINuGet GenDI.SourceGeneratorNuGet GenDI.TestingNuGet GenDI.AnalyzersNuGet GenDI.Testing
Quality Gate StatusBugsCode SmellsCoverageDuplicated Lines (%)Lines of CodeReliability RatingSecurity RatingTechnical DebtMaintainability RatingVulnerabilities
License: MITDocumentation
🚀

Phase 6 Registration Model

Use RM-01..RM-12 features in one generator flow: optional injection, conditional registration, decorators, options, factories and modules.

🏗️

Factory + Module Paradigm

Prefer [InjectableFactory<TService>] for explicit contracts and compose bounded registrations with [InjectableModule].

🛡️

Open-Generic Guardrails

Open-generic generation paths are bypassed by design and surfaced as generator warning GENDISG001 for safe NativeAOT-first behavior.

🌍

Environment + Decorator Support

Activate services by environment with [ConditionalInjectable] and wrap contracts with [DecoratorFor<TService>] in generated registrations.

🧩

Options + Microsoft DI

Bind configuration to IOptions<T> via [OptionConfig] and keep native integration with Microsoft.Extensions.DependencyInjection.

Documentation + CI Visibility

Website/docs now cover RM-01..RM-12 and CI publishes coverage summary with SonarScanner for .NET in the pipeline.

Quick Example

[ServiceInjection]
public interface IOrderService { }

[Injectable<IOrderService>(ServiceLifetime.Scoped, Module = "sales")]
[ConditionalInjectable("Production")]
public sealed partial class OrderService : IOrderService
{
    [InjectOptional]
    public ILogger<OrderService>? Logger { get; init; }
}

[OptionConfig("Sales:Api")]
public sealed class SalesApiOptions;

[InjectableFactory<IClock>(ServiceLifetime.Singleton)]
public static partial class ClockFactory
{
    public static IClock Create() => SystemClock.Instance;
}

builder.Services.AddGenDIServices(modules: "sales"); // if using decorators, call AddGenDIServices after all registrations and before building the provider to ensure correct order of generation and decoration
var app = builder.Build();

See full RM-01..RM-12 guide