Skip to content
davidkallesen edited this page Mar 12, 2026 · 2 revisions

🎯 Atc Source Generators

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.

✨ Key Features

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

✨ 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;

// 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! πŸš€

⚑ Quick Start

1. πŸ“¦ Install the Package

dotnet add package Atc.SourceGenerators

πŸ’‘ Optional (recommended for better IntelliSense):

dotnet add package Atc.SourceGenerators.Annotations

2. 🏷️ Decorate Your Code

Add attributes like [Registration], [OptionsBinding], [MapTo] to your classes and enums.

3. πŸ”¨ Build

dotnet build

βœ… Generated extension methods are ready to use!

πŸ“– See Getting Started for detailed installation and setup instructions.

βš™οΈ Requirements

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

πŸ“– Documentation

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

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

πŸ“„ License

MIT License

🏠 Home

πŸ“– Getting Started

⚑ Generators

🎯 Examples

πŸ”— Integrations

πŸ” Reference

πŸ“‹ Feature Roadmaps


πŸ”— Resources

Clone this wiki locally