Skip to content

Search EricksonLopez.* Ecosystem

Type a library name, NuGet package ID, .NET type, or architectural concept to search across the portal.

Getting Started with EricksonLopez.SharedKernel

L1StableNuGet: v4.0.0Local HEAD: v5.0.1AOT: Full
dotnet add package EricksonLopez.SharedKernel --version 4.0.0

Define your strongly-typed ID using [StrongId<Guid>] (EricksonLopez.DomainPrimitives) or a custom IEntityId<TSelf> record struct (StrongIdGenerator was removed in v4.0.0):

using System;
using EricksonLopez.Events.Contracts;
using EricksonLopez.SharedKernel;
namespace Example.SharedKernelQuickStart;
public readonly record struct AccountId(Guid Value) : IEntityId<AccountId>
{
public bool IsEmpty => Value == Guid.Empty;
public static AccountId New() => new(Guid.NewGuid());
public static AccountId Create(Guid value) => new(value);
public static AccountId Parse(string s, IFormatProvider? provider) => new(Guid.Parse(s, provider));
public static bool TryParse(string? s, IFormatProvider? provider, out AccountId result)
{
if (Guid.TryParse(s, provider, out var guid))
{
result = new(guid);
return true;
}
result = default;
return false;
}
}
public sealed record AccountOpenedEvent(AccountId AccountId) : DomainEvent;
public sealed class BankAccount : AggregateRoot<AccountId>
{
public decimal Balance { get; private set; }
private BankAccount(AccountId id, decimal initialDeposit) : base(id)
{
Balance = initialDeposit;
RaiseDomainEvent(new AccountOpenedEvent(id));
}
public static BankAccount Open(AccountId id, decimal initialDeposit) =>
new(id, initialDeposit);
}