Abstract base for new domain
This commit is contained in:
26
dotnet/AipsCore/Domain/Abstract/DomainEntity.cs
Normal file
26
dotnet/AipsCore/Domain/Abstract/DomainEntity.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using AipsCore.Domain.Common.ValueObjects;
|
||||
|
||||
namespace AipsCore.Domain.Abstract;
|
||||
|
||||
public abstract class DomainEntity<TId> where TId : DomainId
|
||||
{
|
||||
private readonly List<IDomainEvent> _domainEvents = [];
|
||||
|
||||
public TId Id { get; init; }
|
||||
|
||||
protected DomainEntity()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected DomainEntity(TId id)
|
||||
{
|
||||
Id = id;
|
||||
}
|
||||
|
||||
public IReadOnlyList<IDomainEvent> GetDomainEvents() => _domainEvents.ToList();
|
||||
|
||||
public void ClearDomainEvents() => _domainEvents.Clear();
|
||||
|
||||
protected void RaiseDomainEvent(IDomainEvent domainEvent) => _domainEvents.Add(domainEvent);
|
||||
}
|
||||
12
dotnet/AipsCore/Domain/Abstract/IAbstractRepository.cs
Normal file
12
dotnet/AipsCore/Domain/Abstract/IAbstractRepository.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using AipsCore.Domain.Common.ValueObjects;
|
||||
|
||||
namespace AipsCore.Domain.Abstract;
|
||||
|
||||
public interface IAbstractRepository<TEntity, in TId>
|
||||
where TEntity : DomainEntity<TId>
|
||||
where TId : DomainId
|
||||
{
|
||||
Task<TEntity?> GetByIdAsync(TId id, CancellationToken cancellationToken = default);
|
||||
Task SaveAsync(TEntity entity, CancellationToken cancellationToken = default);
|
||||
Task AddAsync(TEntity entity, CancellationToken cancellationToken = default);
|
||||
}
|
||||
6
dotnet/AipsCore/Domain/Abstract/IDomainEvent.cs
Normal file
6
dotnet/AipsCore/Domain/Abstract/IDomainEvent.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace AipsCore.Domain.Abstract;
|
||||
|
||||
public interface IDomainEvent
|
||||
{
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user