Generator Changes at 9/27/2025 8:46:36 AM
This commit is contained in:
13
src/CMSMicroservice.Domain/Common/BaseAuditableEntity.cs
Normal file
13
src/CMSMicroservice.Domain/Common/BaseAuditableEntity.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
namespace CMSMicroservice.Domain.Common;
|
||||
public abstract class BaseAuditableEntity : BaseEntity
|
||||
{
|
||||
public DateTime Created { get; set; }
|
||||
|
||||
public string? CreatedBy { get; set; }
|
||||
|
||||
public DateTime? LastModified { get; set; }
|
||||
|
||||
public string? LastModifiedBy { get; set; }
|
||||
|
||||
public bool IsDeleted { get; set; }
|
||||
}
|
||||
24
src/CMSMicroservice.Domain/Common/BaseEntity.cs
Normal file
24
src/CMSMicroservice.Domain/Common/BaseEntity.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
namespace CMSMicroservice.Domain.Common;
|
||||
public abstract class BaseEntity
|
||||
{
|
||||
public long Id { get; set; }
|
||||
|
||||
private readonly List<BaseEvent> _domainEvents = new();
|
||||
|
||||
public IReadOnlyCollection<BaseEvent> DomainEvents => _domainEvents.AsReadOnly();
|
||||
|
||||
public void AddDomainEvent(BaseEvent domainEvent)
|
||||
{
|
||||
_domainEvents.Add(domainEvent);
|
||||
}
|
||||
|
||||
public void RemoveDomainEvent(BaseEvent domainEvent)
|
||||
{
|
||||
_domainEvents.Remove(domainEvent);
|
||||
}
|
||||
|
||||
public void ClearDomainEvents()
|
||||
{
|
||||
_domainEvents.Clear();
|
||||
}
|
||||
}
|
||||
4
src/CMSMicroservice.Domain/Common/BaseEvent.cs
Normal file
4
src/CMSMicroservice.Domain/Common/BaseEvent.cs
Normal file
@@ -0,0 +1,4 @@
|
||||
namespace CMSMicroservice.Domain.Common;
|
||||
public abstract class BaseEvent : INotification
|
||||
{
|
||||
}
|
||||
38
src/CMSMicroservice.Domain/Common/ValueObject.cs
Normal file
38
src/CMSMicroservice.Domain/Common/ValueObject.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
namespace CMSMicroservice.Domain.Common;
|
||||
public abstract class ValueObject
|
||||
{
|
||||
protected static bool EqualOperator(ValueObject left, ValueObject right)
|
||||
{
|
||||
if (left is null ^ right is null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return left?.Equals(right!) != false;
|
||||
}
|
||||
|
||||
protected static bool NotEqualOperator(ValueObject left, ValueObject right)
|
||||
{
|
||||
return !(EqualOperator(left, right));
|
||||
}
|
||||
|
||||
protected abstract IEnumerable<object> GetEqualityComponents();
|
||||
|
||||
public override bool Equals(object? obj)
|
||||
{
|
||||
if (obj == null || obj.GetType() != GetType())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var other = (ValueObject)obj;
|
||||
return GetEqualityComponents().SequenceEqual(other.GetEqualityComponents());
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return GetEqualityComponents()
|
||||
.Select(x => x != null ? x.GetHashCode() : 0)
|
||||
.Aggregate((x, y) => x ^ y);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user