-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
24 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,18 @@ | ||
using System.ComponentModel.DataAnnotations.Schema; | ||
|
||
namespace Ardalis.SharedKernel; | ||
namespace Ardalis.SharedKernel; | ||
|
||
/// <summary> | ||
/// A base class for DDD Entities. Includes support for domain events dispatched post-persistence. | ||
/// If you prefer GUID Ids, change it here. | ||
/// If you need to support both GUID and int IDs, change to EntityBase<TId> and use TId as the type for Id. | ||
/// </summary> | ||
public abstract class EntityBase | ||
public abstract class EntityBase : HasDomainEventsBase | ||
{ | ||
public int Id { get; set; } | ||
} | ||
|
||
private List<DomainEventBase> _domainEvents = new(); | ||
[NotMapped] | ||
public IEnumerable<DomainEventBase> DomainEvents => _domainEvents.AsReadOnly(); | ||
|
||
protected void RegisterDomainEvent(DomainEventBase domainEvent) => _domainEvents.Add(domainEvent); | ||
internal void ClearDomainEvents() => _domainEvents.Clear(); | ||
public abstract class EntityBase<TId> : HasDomainEventsBase | ||
where TId : struct, IEquatable<TId> | ||
{ | ||
public TId Id { get; set; } | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using System.ComponentModel.DataAnnotations.Schema; | ||
|
||
namespace Ardalis.SharedKernel; | ||
|
||
public abstract class HasDomainEventsBase | ||
{ | ||
private List<DomainEventBase> _domainEvents = new(); | ||
[NotMapped] | ||
public IEnumerable<DomainEventBase> DomainEvents => _domainEvents.AsReadOnly(); | ||
|
||
protected void RegisterDomainEvent(DomainEventBase domainEvent) => _domainEvents.Add(domainEvent); | ||
internal void ClearDomainEvents() => _domainEvents.Clear(); | ||
|
||
} | ||
|