A collection of C# Source Generators for compile-time code generation.
| Package | Description |
|---|---|
IoC/DI registration source generator for Microsoft.Extensions.DependencyInjection.Abstractions |
|
| CLI tool for adding IoC attributes to existing projects |
A C# source generator that extends Microsoft.Extensions.DependencyInjection.Abstractions by generating registration code at compile time.
| Feature | MS.E.DI | SourceGen.Ioc |
|---|---|---|
| Open Generic | Runtime resolution only | ✅ Auto-discovers closed types from usage |
| Nested Open Generic | ❌ | ✅ Auto-discovery + [IocDiscover] |
| Decorator Pattern | ❌ | ✅ With type constraint validation |
| Field/Property/Method Injection | ❌ | ✅ [IocInject] |
| Lifecycle validation | Runtime errors | ✅ Compile-time |
| Circular dependency | Runtime errors | ✅ Compile-time |
dotnet add package SourceGen.Iocusing SourceGen.Ioc;
using Microsoft.Extensions.DependencyInjection;
public interface IMyService;
[IocRegister<IMyService>(ServiceLifetime.Scoped)]
internal class MyService : IMyService;
// Register in DI container
services.AddMyProject(); // Generated extension methodSee full documentation for all features including defaults, keyed services, decorators, open generics, tags, modules, wrappers, factory/instance registration, and compile-time containers.
MIT
