FunctionalDdd.AspSourceGenerator
3.0.0-alpha.72
dotnet add package FunctionalDdd.AspSourceGenerator --version 3.0.0-alpha.72
NuGet\Install-Package FunctionalDdd.AspSourceGenerator -Version 3.0.0-alpha.72
<PackageReference Include="FunctionalDdd.AspSourceGenerator" Version="3.0.0-alpha.72" />
<PackageVersion Include="FunctionalDdd.AspSourceGenerator" Version="3.0.0-alpha.72" />
<PackageReference Include="FunctionalDdd.AspSourceGenerator" />
paket add FunctionalDdd.AspSourceGenerator --version 3.0.0-alpha.72
#r "nuget: FunctionalDdd.AspSourceGenerator, 3.0.0-alpha.72"
#:package FunctionalDdd.AspSourceGenerator@3.0.0-alpha.72
#addin nuget:?package=FunctionalDdd.AspSourceGenerator&version=3.0.0-alpha.72&prerelease
#tool nuget:?package=FunctionalDdd.AspSourceGenerator&version=3.0.0-alpha.72&prerelease
FunctionalDdd.Asp Source Generator
A Roslyn source generator that automatically creates AOT-compatible JSON converters and serializer context entries for types implementing IScalarValue<TSelf, TPrimitive>.
Features
- AOT Compatible: Generated code works with Native AOT compilation
- No Reflection: All type information is resolved at compile time
- Faster Startup: No runtime type scanning or assembly reflection
- Trimming Safe: Code won't be trimmed away since it's explicitly generated
- Automatic Discovery: Finds all types implementing
IScalarValuein your assembly
Usage
Add a reference to the source generator package in your project.
Create a partial
JsonSerializerContextand mark it with[GenerateScalarValueConverters]:
using System.Text.Json.Serialization;
using FunctionalDdd;
[GenerateScalarValueConverters]
[JsonSerializable(typeof(MyDto))]
public partial class AppJsonSerializerContext : JsonSerializerContext
{
}
- The generator will automatically:
- Create AOT-compatible JSON converters for all
IScalarValue<TSelf, TPrimitive>types - Add
[JsonSerializable]attributes for all scalar value types to your context - Generate a
GeneratedScalarValueConverterFactoryyou can use directly
- Create AOT-compatible JSON converters for all
Generated Code
For each type implementing IScalarValue like:
public class CustomerId : ScalarValueObject<CustomerId, Guid>, IScalarValue<CustomerId, Guid>
{
// ...
}
The generator creates:
- A strongly-typed
CustomerIdJsonConverterclass - A
[JsonSerializable(typeof(CustomerId))]attribute on your context - Entry in
GeneratedScalarValueConverterFactoryfor automatic converter resolution
Using the Generated Factory
You can use the generated factory directly:
var options = new JsonSerializerOptions
{
TypeInfoResolver = AppJsonSerializerContext.Default
};
options.Converters.Add(new FunctionalDdd.Generated.GeneratedScalarValueConverterFactory());
Benefits Over Runtime Reflection
| Feature | Runtime Reflection | Source Generator |
|---|---|---|
| AOT Support | ❌ Not compatible | ✅ Full support |
| Startup Time | Slower (type scanning) | Faster (precompiled) |
| Trimming | May break | Trimming safe |
| Memory | Higher (reflection cache) | Lower |
| IDE Support | None | Full IntelliSense |
Requirements
- .NET 6.0 or later
- C# 10.0 or later
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 3.0.0-alpha.72 | 39 | 2/8/2026 |
| 3.0.0-alpha.60 | 38 | 2/4/2026 |
| 3.0.0-alpha.59 | 45 | 2/1/2026 |
| 3.0.0-alpha.56 | 42 | 1/31/2026 |
| 3.0.0-alpha.55 | 42 | 1/31/2026 |