Facet 2.0.0
See the version list below for details.
dotnet add package Facet --version 2.0.0
NuGet\Install-Package Facet -Version 2.0.0
<PackageReference Include="Facet" Version="2.0.0" />
<PackageVersion Include="Facet" Version="2.0.0" />
<PackageReference Include="Facet" />
paket add Facet --version 2.0.0
#r "nuget: Facet, 2.0.0"
#:package Facet@2.0.0
#addin nuget:?package=Facet&version=2.0.0
#tool nuget:?package=Facet&version=2.0.0
Facet
"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.
What is Facetting?
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.
Why Facetting?
- 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
Key Features
- ✅ 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
- ✅ Async mapping support via
IFacetMapConfigurationAsync
- ✅ Hybrid sync/async mapping for optimal performance
- ✅ Collection mapping with sequential and parallel processing
- ✅ Full cancellation token support for async operations
Documentation
The Facet Ecosystem
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: Advanced static mapping configuration support with async capabilities for complex mapping scenarios.
Quick Examples
Basic Projection
[Facet(typeof(User))]
public partial class UserDto { }
// Auto-generates constructor, properties, and LINQ projection
var userDto = user.ToFacet<User, UserDto>();
var userDtos = users.SelectFacets<User, UserDto>();
Custom Sync Mapping
public class UserMapper : IFacetMapConfiguration<User, UserDto>
{
public static void Map(User source, UserDto target)
{
target.FullName = $"{source.FirstName} {source.LastName}";
}
}
[Facet(typeof(User), Configuration = typeof(UserMapper))]
public partial class UserDto
{
public string FullName { get; set; }
}
Async Mapping for I/O Operations
public class UserAsyncMapper : IFacetMapConfigurationAsync<User, UserDto>
{
public static async Task MapAsync(User source, UserDto target, CancellationToken cancellationToken = default)
{
// Async database lookup
target.ProfilePicture = await GetProfilePictureAsync(source.Id, cancellationToken);
// Async API call
target.ReputationScore = await CalculateReputationAsync(source.Email, cancellationToken);
}
}
// Usage
var userDto = await user.ToFacetAsync<User, UserDto, UserAsyncMapper>();
var userDtos = await users.ToFacetsParallelAsync<User, UserDto, UserAsyncMapper>();
EF Core Integration
// Async projection directly in EF Core queries
var userDtos = await dbContext.Users
.Where(u => u.IsActive)
.ToFacetsAsync<User, UserDto>();
Facet — Define less, project more.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- No dependencies.
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Facet:
Package | Downloads |
---|---|
Facet.Extensions
Provider-agnostic extension methods for Facet. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last Updated |
---|---|---|
2.6.1 | 0 | 9/10/2025 |
2.6.0 | 41 | 9/9/2025 |
2.5.0 | 243 | 9/4/2025 |
2.4.8 | 189 | 9/3/2025 |
2.4.7 | 237 | 9/1/2025 |
2.4.6 | 131 | 9/1/2025 |
2.4.5 | 201 | 8/30/2025 |
2.4.4 | 412 | 8/27/2025 |
2.4.3 | 187 | 8/27/2025 |
2.4.2 | 179 | 8/27/2025 |
2.4.1 | 213 | 8/26/2025 |
2.4.0 | 202 | 8/26/2025 |
2.3.0 | 1,543 | 8/20/2025 |
2.2.0 | 158 | 8/20/2025 |
2.1.0 | 266 | 8/18/2025 |
2.0.1 | 761 | 8/5/2025 |
2.0.0 | 154 | 8/4/2025 |
1.9.3 | 194 | 7/4/2025 |
1.9.1 | 155 | 7/3/2025 |
1.9.0 | 153 | 7/3/2025 |
1.8.0 | 252 | 6/4/2025 |
1.7.0 | 210 | 5/6/2025 |
1.6.0 | 179 | 4/27/2025 |
1.5.0 | 217 | 4/26/2025 |
1.4.0 | 143 | 4/25/2025 |
1.3.0 | 170 | 4/24/2025 |
1.2.0 | 175 | 4/24/2025 |
1.1.1 | 175 | 4/23/2025 |
1.1.0 | 180 | 4/23/2025 |
1.0.2 | 374 | 4/23/2025 |
1.0.1 | 190 | 4/23/2025 |
1.0.0 | 189 | 4/23/2025 |
0.1.0 | 182 | 4/22/2025 |