"One part of a subject, situation, object that has many parts."
Facet is a C# source generator that lets you define lightweight projections (DTOs, API models, etc.) directly from your domain models — without writing boilerplate.
It generates partial classes, records, structs, or record structs with constructors, optional LINQ projections, and even supports custom mappings — all at compile time, with zero runtime cost.
Facetting is the process of defining focused views of a larger model at compile time.
Instead of manually writing separate DTOs, mappers, and projections, Facet allows you to declare what you want to keep — and generates everything else.
You can think of it like carving out a specific facet of a gem:
- The part you care about
- Leaving the rest behind.
- Reduce duplication across DTOs, projections, and ViewModels
- Maintain strong typing with no runtime cost
- Stay DRY (Don't Repeat Yourself) without sacrificing performance
- Works seamlessly with LINQ providers like Entity Framework
- ✅ Generate classes, records, structs, or record structs from existing types
- ✅ Exclude fields/properties you don't want (create a Facetted view of your model)
- ✅ Include/redact public fields
- ✅ Auto-generate constructors for fast mapping
- ✅ LINQ projection expressions
(Expression<Func<TSource,TTarget>>)
- ✅ Custom mapping via
IFacetMapConfiguration
Facet is modular and consists of several NuGet packages:
-
Facet: The core source generator. Generates DTOs, projections, and mapping code.
-
Facet.Extensions: Provider-agnostic extension methods for mapping and projecting (works with any LINQ provider, no EF Core dependency).
-
Facet.Extensions.EFCore: Async extension methods for Entity Framework Core (requires EF Core 6+).
-
Facet.Mapping: (Optional) Advanced static mapping configuration support for Facet.
Facet — Define less, project more.