FunctionalDDD.CommonValueObjects 1.1.0-alpha.28

This is a prerelease version of FunctionalDDD.CommonValueObjects.
There is a newer version of this package available.
See the version list below for details.
dotnet add package FunctionalDDD.CommonValueObjects --version 1.1.0-alpha.28                
NuGet\Install-Package FunctionalDDD.CommonValueObjects -Version 1.1.0-alpha.28                
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="FunctionalDDD.CommonValueObjects" Version="1.1.0-alpha.28" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add FunctionalDDD.CommonValueObjects --version 1.1.0-alpha.28                
#r "nuget: FunctionalDDD.CommonValueObjects, 1.1.0-alpha.28"                
#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.
// Install FunctionalDDD.CommonValueObjects as a Cake Addin
#addin nuget:?package=FunctionalDDD.CommonValueObjects&version=1.1.0-alpha.28&prerelease

// Install FunctionalDDD.CommonValueObjects as a Cake Tool
#tool nuget:?package=FunctionalDDD.CommonValueObjects&version=1.1.0-alpha.28&prerelease                

Common Value Object

This library contains common value objects used across the applications. At this point there are three classes:

  • EmailAddress - Email address value object that validates the email address format.
  • RequiredString - String value object that cannot be null or empty.
  • RequiredGuid - Guid value object that cannot be null or default.

Usage

RequiredString and RequiredGuid uses source code generation to generate the New method and other boilerplate code. Make sure it is declared as partial class so that the source code generator can do the rest.

Here is an example of how to use RequiredString:

public partial class TrackingId : RequiredString
{
}

The source code generator will generate the following

public partial class TrackingId : RequiredString
{
    protected static readonly Error CannotBeEmptyError = Error.Validation("Tracking Id cannot be empty.", "trackingId");

    private TrackingId(string value) : base(value)
    {
    }

    public static explicit operator TrackingId(string trackingId) => New(trackingId).Value;

    public static Result<TrackingId> New(string? requiredStringOrNothing) =>
        requiredStringOrNothing
            .EnsureNotNullOrWhiteSpace(CannotBeEmptyError)
            .Map(str => new TrackingId(str));
}

Here is an example of how to use RequiredGuid:

public partial class EmployeeId : RequiredGuid
{
}

The source code generator will generate the following

public partial class EmployeeId : RequiredGuid
{
    protected static readonly Error CannotBeEmptyError = Error.Validation("Employee Id cannot be empty.", "employeeId");

    private EmployeeId(Guid value) : base(value)
    {
    }

    public static explicit operator EmployeeId(Guid employeeId) => New(employeeId).Value;

    public static EmployeeId NewUnique() => new(Guid.NewGuid());

    public static Result<EmployeeId> New(Guid? requiredGuidOrNothing) =>
        requiredGuidOrNothing
            .ToResult(CannotBeEmptyError)
            .Ensure(x => x != Guid.Empty, CannotBeEmptyError)
            .Map(guid => new EmployeeId(guid));

    public static Result<EmployeeId> New(string? stringOrNull)
    {
         Guid parsedGuid = Guid.Empty;
         return stringOrNull
            .ToResult(CannotBeEmptyError)
            .Ensure(x => Guid.TryParse(x, out parsedGuid), Error.Validation("string is not in valid format.", "employeeId"))
            .Ensure(_ => parsedGuid != Guid.Empty, CannotBeEmptyError)
            .Map(guid => new EmployeeId(parsedGuid));
    }
}
Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on FunctionalDDD.CommonValueObjects:

Package Downloads
FunctionalDdd.SampleUserLibrary

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.0.0-alpha.52 48 11/7/2024
2.0.0-alpha.48 42 11/2/2024
2.0.0-alpha.47 43 10/30/2024
2.0.0-alpha.44 100 10/18/2024
2.0.0-alpha.42 53 10/14/2024
2.0.0-alpha.39 65 6/27/2024
2.0.0-alpha.38 65 4/24/2024
2.0.0-alpha.33 65 4/17/2024
2.0.0-alpha.26 69 4/9/2024
2.0.0-alpha.21 67 4/1/2024
2.0.0-alpha.19 68 3/5/2024
2.0.0-alpha.18 78 2/28/2024
2.0.0-alpha.17 71 2/26/2024
2.0.0-alpha.15 82 1/30/2024
2.0.0-alpha.8 66 1/27/2024
2.0.0-alpha.6 96 1/5/2024
1.1.1 569 11/15/2023
1.1.0-alpha.32 104 11/2/2023
1.1.0-alpha.30 212 10/31/2023
1.1.0-alpha.28 95 10/28/2023
1.1.0-alpha.27 94 10/28/2023
1.1.0-alpha.24 83 10/20/2023
1.1.0-alpha.23 90 10/13/2023
1.1.0-alpha.21 84 10/1/2023
1.1.0-alpha.20 82 9/30/2023
1.1.0-alpha.19 80 9/30/2023
1.1.0-alpha.18 90 9/29/2023
1.1.0-alpha.17 83 9/22/2023
1.1.0-alpha.13 82 9/16/2023
1.1.0-alpha.4 150 6/9/2023
1.1.0-alpha.3 92 6/8/2023
1.0.1 528 5/12/2023
0.1.0-alpha.40 123 4/6/2023
0.1.0-alpha.39 123 4/3/2023
0.1.0-alpha.38 152 4/2/2023
0.1.0-alpha.37 129 3/31/2023
0.1.0-alpha.35 123 3/29/2023
0.1.0-alpha.34 108 3/28/2023
0.1.0-alpha.32 144 3/18/2023
0.1.0-alpha.30 135 3/11/2023
0.1.0-alpha.27 129 3/7/2023
0.1.0-alpha.24 132 2/15/2023
0.1.0-alpha.22 117 2/15/2023
0.1.0-alpha.20 132 2/13/2023
0.1.0-alpha.19 93 2/13/2023
0.0.1-alpha.14 154 1/4/2023
0.0.1-alpha.4 134 12/30/2022
0.0.1-alpha.3 142 12/23/2022
0.0.1-alpha 507 12/21/2022