ValueOf.Extensions.EFCore 1.0.5

dotnet add package ValueOf.Extensions.EFCore --version 1.0.5
                    
NuGet\Install-Package ValueOf.Extensions.EFCore -Version 1.0.5
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ValueOf.Extensions.EFCore" Version="1.0.5" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ValueOf.Extensions.EFCore" Version="1.0.5" />
                    
Directory.Packages.props
<PackageReference Include="ValueOf.Extensions.EFCore" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add ValueOf.Extensions.EFCore --version 1.0.5
                    
#r "nuget: ValueOf.Extensions.EFCore, 1.0.5"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package ValueOf.Extensions.EFCore@1.0.5
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=ValueOf.Extensions.EFCore&version=1.0.5
                    
Install as a Cake Addin
#tool nuget:?package=ValueOf.Extensions.EFCore&version=1.0.5
                    
Install as a Cake Tool

ValueOf.Extensions

This library contains a set of adapters/utilities you might need when using the popular ValueOf library.

Below is a list of features supported in each package:

Package: ValueOf.Extensions

System.Text.Json JSON serialization/deserialization with ValueOfJsonAdapterFactory

var options = new JsonSerializerOptions
{
    Converters = { new ValueOfJsonAdapterFactory() },
};

or in ASP.NET Core:

builder.Services.AddControllers().AddJsonOptions(options =>
{
    options.JsonSerializerOptions.Converters.Add(new ValueOfJsonAdapterFactory());
});

TypeConverter with ValueOfTypeConverter<TU, T>

This is needed if you want to be able to parse a ValueOf type from strings. Typically you'll need it when you want to bind API parameters e.g. [FromRoute] UserId id & [FromQuery] EmailAddress email in ASP.NET Core.

You can use this provided extension method to add all ValueOf types collectively.

    ValueOfTypeExtensions.ConfigureValueOfTypeConverters(typeof(UserId).Assembly);

Package: ValueOf.Extensions.NewtonsoftJson

If you are using Newtonsoft.JSON, this package fixes serialization/deserialization with a custom JsonConverter ValueOfNewtonsoftConverter.

var settings = new JsonSerializerSettings
{
    Converters = [new ValueOfNewtonsoftConverter()],
};

Package: ValueOf.Extensions.Dapper

With this package, you can have your column be of ValueOf types.

You can use the provided extension method to register all ValueOfDapperTypeHandlers from assemblies with ease:

ValueOfDapperExtensions.ConfigureValueOfDapperTypeHandlers(typeof(UserId).Assembly);

Package: ValueOf.Extensions.EFCore

This package adds ValueConverter automatically for your ValueOf types if you use them in your EF.Core entity columns. The usage is simple:

    protected override void ConfigureConventions(ModelConfigurationBuilder b)
    {
        base.ConfigureConventions(b);
        b.ConfigureValueOfConversions(typeof(UserId).Assembly);
    }

Package: ValueOf.Extensions.Swagger

If you ValueOf, swagger will still consider a ValueOf type a complex type instead of a simple type. This package helps you fix that by picking the most suitable type & format based on the underlying type.

This extension method helps you map all your ValueOf types to the correct schema.

    opts.MapValueOfTypesInAssemblies(null, typeof(EmailAddress).Assembly);

If type & format picked for you doesn't suit your needs, you can use the SwaggerTypeMap? typeMapOverride parameter in MapValueOfTypesInAssemblies to customize.

NOTE: currently I only handled Swashbuckle.AspNetCore. Let me know or send me PR if you want integration for other Swagger/Open API solutions.

Package: ValueOf.Extensions.ParsableGenerator

There are many ways to bind route or query parameters to your custom types in minimal APIs but unfortunately TypeConverter is not one of them. A non-generator solution would have worked if this issue is fixed. Anyway, this source code generator will generate methods implementing IParsable<T> for you automatically.

You just need to include this nuget package & mark your ValueOf subclass as partial.

Additionally configure for System.Text.JSON as follows:

builder.Services.Configure<Microsoft.AspNetCore.Http.Json.JsonOptions>(options =>
    options.SerializerOptions.Converters.Add(new ValueOfJsonAdapterFactory()));

Note that System.Text.JSON configuration for Minimal APIs is different from that for the conventional controllers.

Examples

Do check out the ValueOf.Extensions.Examples directory as it contains an comprehensive ASP.NET Core project demonstrating capabilities of all nuget packages in this project.

References

see Document a System.Text.Json TypeConverter to JsonConverter Adapter · Issue #1761 · dotnet/runtime

and System.Text.Json does not support TypeConverters · Issue #38812 · dotnet/runtime

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
1.0.5 512 7/22/2025
1.0.4 488 7/22/2025
1.0.3 491 7/22/2025
1.0.2 116 7/17/2025
0.0.0-alpha.0 114 7/17/2025