This commit is contained in:
john 2025-05-03 15:38:57 +02:00
commit ab2e20f7e1
72 changed files with 2000 additions and 0 deletions

View file

@ -0,0 +1,3 @@
namespace Femto.Common.Domain;
public class DomainException(string message) : Exception(message);

View file

@ -0,0 +1,21 @@
namespace Femto.Common.Domain;
public abstract class Entity
{
private readonly ICollection<IDomainEvent> _domainEvents = [];
protected void AddDomainEvent(IDomainEvent evt)
{
this._domainEvents.Add(evt);
}
public IList<IDomainEvent> DomainEvents => this._domainEvents.ToList();
public void ClearDomainEvents() => this._domainEvents.Clear();
protected void CheckRule(IRule rule)
{
if (!rule.Check())
throw new RuleBrokenException(rule.Message);
}
}

View file

@ -0,0 +1,13 @@
using MediatR;
namespace Femto.Common.Domain;
public interface IDomainEvent : INotification
{
public Guid EventId { get; }
}
public abstract record DomainEvent : IDomainEvent
{
public Guid EventId { get; } = Guid.NewGuid();
}

View file

@ -0,0 +1,8 @@
namespace Femto.Common.Domain;
public interface IRule
{
bool Check();
string Message { get; }
}

View file

@ -0,0 +1,3 @@
namespace Femto.Common.Domain;
public class RuleBrokenException(string message) : DomainException(message);