DomainModelKit 1.0.0
dotnet add package DomainModelKit --version 1.0.0
NuGet\Install-Package DomainModelKit -Version 1.0.0
<PackageReference Include="DomainModelKit" Version="1.0.0" />
paket add DomainModelKit --version 1.0.0
#r "nuget: DomainModelKit, 1.0.0"
// Install DomainModelKit as a Cake Addin #addin nuget:?package=DomainModelKit&version=1.0.0 // Install DomainModelKit as a Cake Tool #tool nuget:?package=DomainModelKit&version=1.0.0
DomainModelKit
Common Domain Driven Desing patterns for building domain models and domain layer of clean architecture
Download
dotnet add package DomainModelKit
BaseDomainException
BaseDomainException
is an abstract class representing a base class for domain exceptions. It extends Exception
.
Guard
The Guard class provides a set of static methods that are used to check preconditions in a domain model. These methods are used to ensure that a given value meets certain requirements and throw exceptions if the requirements are not met. The class contains a set of methods to check if a given value is empty or null, if it's length is within a specific range, if it's within a specific range of values, if it's a valid URL, if it matches a specific regular expression, if it's null, if it's not equal to a specific value, if it's a valid email address, if it's a valid date range, if it's not a default value, if it's a positive value, and if it's a valid enum value.
IFactory
The IFactory interface defines a contract for a factory that produces entities that are IAggregateRoot implementations. The interface has a single method, Build(), that returns an instance of the entity produced by the factory.
IAggregateRoot
The IAggregateRoot interface defines the contract for an aggregate root in the domain model. Aggregate roots are the entities that form the core of the domain model and represent the consistency boundary within which all the other domain entities and value objects exist.
As an empty interface, IAggregateRoot does not provide any implementation or members. Its sole purpose is to serve as a marker interface, indicating that the implementing class is an aggregate root.
Enumeration
Enumeration class is an abstract base class that provides a way to define types that represent a fixed set of values. This class helps in enforcing the validation rules by creating fixed-value constants that can be used across the application.
public class GenderType : Enumeration
{
public static GenderType Male = new GenderType(1, "Male");
public static GenderType Female = new GenderType(2, "Female");
public GenderType(int value, string name)
: base(value, name)
{
}
}
Now, you can use the GenderType enumeration in your application to represent the gender of a person.
To get all the values of the GenderType enumeration, use the GetAll method as shown below:
var genderTypes = GenderType.GetAll<GenderType>();
You can also get the gender type by name or value using the FromName and FromValue methods as shown below:
var male = GenderType.FromName<GenderType>("Male");
var female = GenderType.FromValue<GenderType>(2);
To get the name of a gender type from its value, use the NameFromValue method as shown below:
var genderName = GenderType.NameFromValue<GenderType>(1);
You can also check if a gender type has a specific value using the HasValue method as shown below:
var hasMale = GenderType.HasValue<GenderType>(1);
ValueObject
A base class for creating value objects that can be used in DDD (Domain Driven Design) applications. ValueObject provides an implementation of equality checks between two value objects.
To create a value object, create a new class that inherits from ValueObject and define its fields.
public class Money : ValueObject
{
public decimal Amount { get; }
public string Currency { get; }
public Money(decimal amount, string currency)
{
this.Amount = amount;
this.Currency = currency;
}
}
After creating the value object, the Equals and GetHashCode methods will be automatically implemented using reflection. This will compare the fields of two objects to determine if they are equal.
var money1 = new Money(100m, "USD");
var money2 = new Money(100m, "USD");
var areEqual = money1.Equals(money2); // true
var hashCodesEqual = money1.GetHashCode() == money2.GetHashCode(); // true
API
public override bool Equals(object? other);
public override int GetHashCode();
public static bool operator ==(ValueObject first, ValueObject second);
public static bool operator !=(ValueObject first, ValueObject second);
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. 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. |
.NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- 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 |
---|---|---|
1.0.0 | 209 | 2/24/2023 |