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,7 @@
namespace Femto.Common.Attributes;
[AttributeUsage(AttributeTargets.Class, Inherited = false)]
public class EventTypeAttribute(string name) : Attribute
{
public string Name { get; } = name;
}

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);

View file

@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MediatR" Version="12.5.0" />
</ItemGroup>
<ItemGroup>
<Folder Include="Infrastructure\" />
</ItemGroup>
</Project>

View file

@ -0,0 +1,8 @@
using MediatR;
namespace Femto.Common.Integration;
public interface IIntegrationEvent : INotification
{
public Guid EventId { get; }
}