π― Atc Source Generators
March 13, 2026 Β· View on GitHub
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.
Why Choose Atc Source Generators?
- π― Zero boilerplate - Attribute-based approach eliminates repetitive code
- β‘ Compile-time generation - Catch errors during build, not at runtime
- π Native AOT ready - Zero reflection, fully trimming-safe for modern .NET
- π§© Multi-project architecture - Smart naming for clean layered applications
- π‘οΈ Type-safe - Full IntelliSense and compile-time validation
- π¦ Single package - Install once, use all generators
π Source Generators
| Generator | Attribute | What It Does |
|---|---|---|
| β‘ DependencyRegistration | [Registration] | Automatic DI service registration with auto-detection, keyed services, factories, decorators |
| βοΈ OptionsBinding | [OptionsBinding] | Configuration binding with validation, change callbacks, named options |
| πΊοΈ ObjectMapping | [MapTo(typeof(T))] | Object-to-object mapping with bidirectional, nested, and collection support |
| π EnumMapping | [MapTo(typeof(T))] | Enum-to-enum mapping with special case detection (None β Unknown) |
| π AnnotationConstants | (automatic) | Compile-time access to DataAnnotation metadata without reflection |
β¨ See It In Action
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;
builder.Services.AddDependencyRegistrationsFromDomain();
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! π
π¦ Installation
dotnet add package Atc.SourceGenerators
Optional (recommended for better IntelliSense):
dotnet add package Atc.SourceGenerators.Annotations
βοΈ Requirements
- .NET 10 SDK required at build time (Roslyn 5.0.0)
- Projects can still target .NET 9, .NET 8, or earlier
- This is a build-time requirement only, not a runtime requirement
π Documentation
Full documentation is available in the Wiki:
| Page | Description |
|---|---|
| Getting Started | Installation, packages, and SDK requirements |
| Dependency Registration | Automatic DI with [Registration] β auto-detection, keyed services, factories, decorators, transitive registration |
| Options Binding | Configuration binding with [OptionsBinding] β validation, change callbacks, named options, child sections |
| Object Mapping | Object mapping with [MapTo] β bidirectional, nested objects, collections, projections, property strategies |
| Enum Mapping | Enum mapping with [MapTo] β special case detection, bidirectional, case-insensitive |
| Annotation Constants | Compile-time DataAnnotation metadata β zero reflection, Blazor-ready, Native AOT |
| Sample Projects | Working code examples for each generator |
| PetStore API Example | Full application using all generators with OpenAPI/Scalar |
π¨ Building
dotnet build
π§ͺ Testing
dotnet test
π€ Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
π License
[License information here]