Typely: Unleashing the power of value object creation with a fluent Api. This package contains type generators.
$ dotnet add package Typely.GeneratorsTypely: Unleashing the power of value object creation with a fluent Api.
public class TypesSpecification : ITypelySpecification
{
public void Create(ITypelyBuilder builder)
{
builder.OfInt().For("Votes");
builder.OfString().For("Code").Length(4).NotEqual("0000");
builder.OfString()
.For("UserId")
.WithNamespace("UserAggregate")
.WithName("Owner identifier")
.NotEmpty()
.NotEqual("0").WithMessage("{Name} cannot be equal to {ComparisonValue}.").WithErrorCode("ERR001")
.MaxLength(20);
builder.OfString()
.For("Monday")
.AsClass()
.WithName(() => LocalizedNames.Moment)
.MinLength(1).WithMessage(() => LocalizedMessages.MinLengthCustom)
.MaxLength(20).WithMessage(() => LocalizedMessages.MaxLengthCustom);
}
}
Install packages
dotnet add package Typely.Core
dotnet add package Typely.Generators
Create a class inheriting from ITypelySpecification
public class TypesSpecification : ITypelySpecification
{
public void Create(ITypelyBuilder builder)
{
builder.OfString().For("FirstName").NotEmpty();
}
}
Usage
var firstName = FirstName.From("Adam");
FirstName.From(""); //Throws ValidationException
if(!FirstName.TryFrom("value", out FirstName instance, out ValidationError? validationError))
{
// Handle error
}