添加项目文件。
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
namespace IM.DomainCommons
|
||||
{
|
||||
public class AggregateRootEntity : BaseEntity, IAggregateRoot, ISoftDelete, IHasCreationTime, IHasDeletionTime, IHasModificationTime
|
||||
{
|
||||
public bool IsDeleted { get; private set; }
|
||||
|
||||
public DateTimeOffset CreationTime { get; private set; } = DateTime.Now;
|
||||
|
||||
public DateTimeOffset? Deletion { get; private set; }
|
||||
|
||||
public DateTimeOffset? ModificationTime { get; set; }
|
||||
|
||||
public void SoftDelete()
|
||||
{
|
||||
Deletion = DateTime.Now;
|
||||
IsDeleted = true;
|
||||
}
|
||||
|
||||
public void NotifyModified()
|
||||
{
|
||||
ModificationTime = DateTime.Now;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
using MassTransit;
|
||||
using MediatR;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace IM.DomainCommons
|
||||
{
|
||||
public class BaseEntity : IEntity, IDomainEvents
|
||||
{
|
||||
/// <summary>
|
||||
/// 这里使用连续guid,防止数据库性能问题
|
||||
/// </summary>
|
||||
public Guid Id { get; private set; } = NewId.NextGuid();
|
||||
|
||||
[NotMapped]
|
||||
public List<INotification> domainEvents = [];
|
||||
|
||||
public void AddDomainEvent(INotification eventItem)
|
||||
{
|
||||
domainEvents.Add(eventItem);
|
||||
}
|
||||
|
||||
public void AddDomainEventIfAbsent(INotification eventItem)
|
||||
{
|
||||
if (!domainEvents.Contains(eventItem))
|
||||
{
|
||||
domainEvents.Add(eventItem);
|
||||
}
|
||||
}
|
||||
|
||||
public void ClearDomainEvents()
|
||||
{
|
||||
domainEvents.Clear();
|
||||
}
|
||||
|
||||
public IEnumerable<INotification> GetDomainEvents()
|
||||
{
|
||||
return domainEvents;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace IM.DomainCommons
|
||||
{
|
||||
public class DomainException : Exception
|
||||
{
|
||||
public DomainException(string message) : base(message)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace IM.DomainCommons
|
||||
{
|
||||
public interface IAggregateRoot
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using MediatR;
|
||||
|
||||
namespace IM.DomainCommons
|
||||
{
|
||||
public interface IDomainEvents
|
||||
{
|
||||
IEnumerable<INotification> GetDomainEvents();
|
||||
void AddDomainEvent(INotification eventItem);
|
||||
void AddDomainEventIfAbsent(INotification eventItem);
|
||||
void ClearDomainEvents();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace IM.DomainCommons
|
||||
{
|
||||
public interface IEntity
|
||||
{
|
||||
Guid Id { get; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace IM.DomainCommons
|
||||
{
|
||||
public interface IHasCreationTime
|
||||
{
|
||||
DateTimeOffset CreationTime { get; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace IM.DomainCommons
|
||||
{
|
||||
public interface IHasDeletionTime
|
||||
{
|
||||
DateTimeOffset? Deletion { get; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace IM.DomainCommons
|
||||
{
|
||||
public interface IHasModificationTime
|
||||
{
|
||||
DateTimeOffset? ModificationTime { get; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="MediatR" Version="14.1.0" />
|
||||
<PackageReference Include="NewId" Version="4.0.1" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace IM.DomainCommons
|
||||
{
|
||||
public interface ISoftDelete
|
||||
{
|
||||
bool IsDeleted { get; }
|
||||
void SoftDelete();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user