first commit
This commit is contained in:
36
MyNewProjectName.Domain/Common/BaseEntity.cs
Normal file
36
MyNewProjectName.Domain/Common/BaseEntity.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
namespace MyNewProjectName.Domain.Common;
|
||||
|
||||
/// <summary>
|
||||
/// Base entity with common properties for all entities
|
||||
/// </summary>
|
||||
public abstract class BaseEntity
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
|
||||
private readonly List<IDomainEvent> _domainEvents = new();
|
||||
|
||||
public IReadOnlyCollection<IDomainEvent> DomainEvents => _domainEvents.AsReadOnly();
|
||||
|
||||
public void AddDomainEvent(IDomainEvent domainEvent)
|
||||
{
|
||||
_domainEvents.Add(domainEvent);
|
||||
}
|
||||
|
||||
public void RemoveDomainEvent(IDomainEvent domainEvent)
|
||||
{
|
||||
_domainEvents.Remove(domainEvent);
|
||||
}
|
||||
|
||||
public void ClearDomainEvents()
|
||||
{
|
||||
_domainEvents.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Marker interface for domain events
|
||||
/// </summary>
|
||||
public interface IDomainEvent
|
||||
{
|
||||
DateTime OccurredOn { get; }
|
||||
}
|
||||
Reference in New Issue
Block a user