init
This commit is contained in:
commit
ab2e20f7e1
72 changed files with 2000 additions and 0 deletions
3
Femto.Common/Domain/DomainException.cs
Normal file
3
Femto.Common/Domain/DomainException.cs
Normal file
|
@ -0,0 +1,3 @@
|
|||
namespace Femto.Common.Domain;
|
||||
|
||||
public class DomainException(string message) : Exception(message);
|
21
Femto.Common/Domain/Entity.cs
Normal file
21
Femto.Common/Domain/Entity.cs
Normal 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);
|
||||
}
|
||||
}
|
13
Femto.Common/Domain/IDomainEvent.cs
Normal file
13
Femto.Common/Domain/IDomainEvent.cs
Normal 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();
|
||||
}
|
8
Femto.Common/Domain/IRule.cs
Normal file
8
Femto.Common/Domain/IRule.cs
Normal file
|
@ -0,0 +1,8 @@
|
|||
namespace Femto.Common.Domain;
|
||||
|
||||
public interface IRule
|
||||
{
|
||||
bool Check();
|
||||
|
||||
string Message { get; }
|
||||
}
|
3
Femto.Common/Domain/RuleBrokenException.cs
Normal file
3
Femto.Common/Domain/RuleBrokenException.cs
Normal file
|
@ -0,0 +1,3 @@
|
|||
namespace Femto.Common.Domain;
|
||||
|
||||
public class RuleBrokenException(string message) : DomainException(message);
|
Loading…
Add table
Add a link
Reference in a new issue