-
Notifications
You must be signed in to change notification settings - Fork 0
Home
A collection of Roslyn C# source generators for .NET that eliminate boilerplate code and improve developer productivity. All generators are designed with Native AOT compatibility in focus, enabling faster startup times, smaller deployment sizes, and optimal performance for modern cloud-native applications.
| Area | Feature | Description |
|---|---|---|
| π DI Registration | π― Auto-Detection | Decorate with [Registration] β interfaces auto-detected, lifetimes configurable |
| π Keyed & Factory | Keyed services, factory methods, decorators, conditional registration | |
| π Transitive | One call registers services from all referenced assemblies | |
| βοΈ Options Binding | π§ Smart Sections | Section names inferred from class, SectionName const, or explicit path |
| π Validation | DataAnnotations, ValidateOnStart, custom IValidateOptions<T>
|
|
| π OnChange | Auto-generated callbacks for runtime configuration updates | |
| πΊοΈ Object Mapping | π Bidirectional | Forward + reverse mappings from a single [MapTo] attribute |
| πͺ Nested & Chains | Automatic nested object mapping and multi-layer chains | |
| π Projections | IQueryable projections for EF Core server-side optimization | |
| π Enum Mapping | π Special Cases | None β Unknown β Default auto-detected |
| π€ Case-Insensitive | Matches regardless of casing differences | |
| π Annotations | π Zero Reflection | Compile-time access to DataAnnotation metadata |
| π― Blazor-Ready | Perfect for dynamic forms without runtime reflection |
All generators work together seamlessly in a typical 3-layer architecture:
// 1οΈβ£ Domain Layer - Your business logic
[MapTo(typeof(PetStatusDto), Bidirectional = true)]
public enum PetStatus { Available, Adopted }
[MapTo(typeof(PetDto))]
public partial class Pet
{
public Guid Id { get; set; }
public string Name { get; set; } = string.Empty;
public PetStatus Status { get; set; }
}
[Registration(Lifetime.Scoped)]
public class PetService : IPetService
{
public async Task<Pet> GetPetAsync(Guid id) { /* ... */ }
}
[OptionsBinding("PetStore")]
public partial class PetStoreOptions
{
[Required] public int MaxPetsPerPage { get; set; }
}
// 2οΈβ£ Program.cs - One line per concern
using Atc.DependencyInjection;
using Atc.Mapping;
// Register all services from Domain layer
builder.Services.AddDependencyRegistrationsFromDomain();
// Bind all options from Domain layer
builder.Services.AddOptionsFromDomain(builder.Configuration);
// 3οΈβ£ Usage - Clean and type-safe
app.MapGet("/pets/{id}", async (Guid id, IPetService service) =>
{
var pet = await service.GetPetAsync(id);
return Results.Ok(pet.MapToPetDto()); // β¨ Generated mapping
});Result: Zero boilerplate, full type safety, Native AOT ready! π
dotnet add package Atc.SourceGeneratorsπ‘ Optional (recommended for better IntelliSense):
dotnet add package Atc.SourceGenerators.AnnotationsAdd attributes like [Registration], [OptionsBinding], [MapTo] to your classes and enums.
dotnet buildβ Generated extension methods are ready to use!
π See Getting Started for detailed installation and setup instructions.
This package uses Roslyn 5.0.0 (.NET 10) for source generation.
- π οΈ .NET 10 SDK required at build time
- π― Projects can still target .NET 9, .NET 8, or earlier
- π‘ This is a build-time requirement only, not a runtime requirement
| Page | Description |
|---|---|
| π Getting Started | Installation, packages, and SDK requirements |
| π Working with Dependency Registration | Automatic DI service registration with [Registration]
|
| βοΈ Working with Options Binding | Configuration binding with [OptionsBinding]
|
| πΊοΈ Working with Object Mapping | Object-to-object mapping with [MapTo]
|
| π Working with Enum Mapping | Enum-to-enum mapping with special case handling |
| π Working with Annotation Constants | Compile-time access to DataAnnotation metadata |
| π» Sample Projects | Working code examples for each generator |
| πΎ PetStore API Example | Full application using all generators together |
Contributions are welcome! Please feel free to submit a Pull Request.
π Home
- π Getting Started
- π Migration Guide
- π Working with Dependency Registration
- βοΈ Working with Options Binding
- πΊοΈ Working with Object Mapping
- π Working with Enum Mapping
- π Working with Annotation Constants
- π¦ Sample Projects
- πΎ PetStore API Example
- π Attribute API Reference
- π©Ί Diagnostics Reference
β οΈ Common Patterns and Anti-Patterns- π Native AOT Compatibility
- π§ Troubleshooting
- π Dependency Registration Feature Roadmap
- βοΈ Options Binding Feature Roadmap
- πΊοΈ Object Mapping Feature Roadmap
- π Annotation Constants Feature Roadmap
- π¦ GitHub Repository
- π₯ NuGet Package
- π Report Issues