init
This commit is contained in:
commit
ab2e20f7e1
72 changed files with 2000 additions and 0 deletions
7
Femto.Common/Attributes/EventTypeAttribute.cs
Normal file
7
Femto.Common/Attributes/EventTypeAttribute.cs
Normal 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;
|
||||
}
|
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);
|
16
Femto.Common/Femto.Common.csproj
Normal file
16
Femto.Common/Femto.Common.csproj
Normal 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>
|
8
Femto.Common/Integration/IIntegrationEvent.cs
Normal file
8
Femto.Common/Integration/IIntegrationEvent.cs
Normal file
|
@ -0,0 +1,8 @@
|
|||
using MediatR;
|
||||
|
||||
namespace Femto.Common.Integration;
|
||||
|
||||
public interface IIntegrationEvent : INotification
|
||||
{
|
||||
public Guid EventId { get; }
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue