πWelcome!
Type less, do more
Unleashing the power of value object creation with a fluent Api.
Example
Prerequisites
Supported .NET versions
.NET 7.0 and greater
Getting started
Install packages
Create a class inheriting from
ITypelySpecification
Usage
Json Serialization
Serialization using System.Text.Json is supported by default and will only write the underlying value.
ASP.NET Core
To support validation handling and MVC model binding, include Typely.AspNetCore
in your projects.
Nuget package
Model binding
By default Minimal Apis are supported by implementing a
TryParse
function for generated types.Post requests are supported by
TypelyJsonConverter
.Other bindings are supported by
TypelyTypeConverter
.
These are included by default with Typely.Core
.
Model state
If you want to add validation errors into the model state of MVC during the binding phase of the request, configure the option below:
Configuration
It supports many validation errors without using exceptions.
Validation errors
The following middleware allows you to return neatly structured Json error responses compatible with Microsoft.AspNetCore.Http.HttpValidationProblemDetails
.
Configuration
It works by catching a ValidationException
thrown by Typely and returns a list of errors associated to their value object type name as well as the templates used, if you want to modfify the messages in your client application.
Example of response:
OpenAPI
To add support for OpenAPI specs and Swagger UI, include Typely.AspNetCore.Swashbuckle
in your projects.
Nuget package
Configuration
Entity Framework Core
To use your value objects with EF Core, include Typely.EfCore
in your projects.
Nuget package
Configuration
Apply Typely conventions to your DbContext
to automatically configure the database. By default, the conventions will tell EF Core how to save and load your value objects and set the maximum data length.
If you don't use conventions, you can configure your types manually. Typely will generate a MaxLength
property when using a validation that sets the maximum length.
You can also override the default conventions:
Why Typely?
The entire boiler plate is generated for you. Example here.
Supports value comparison with:
IEquatable<T>
Operators
!=
and==
Support for sorting with:
IComparable<T>
IComparable
Support for creating and validating value objects in a generic way.
Typely doesn't use the generic
EqualityComparer
and is therefore faster than records.
Built-in localized validations. You define the rules of the model once.
Built-in type conversion.
Accept value objects directly in your APIs.
No need to manually create theses objects.
No need to validate theirs values because they can only be created if they are valid during deserialization.
Save or read your value objects to or from the database without effort.
Lets you extend your value objects easily:
With the use of the interface
ITypelyValue<TValue, TThis>
Or by creating a partial class of the same namespace and type.
Last updated