Browse Source

Merge pull request #561 from Alexbits/hotfix/EntityEncapsulationFix

Improved encapsulation of DomainEvents collection in Entity class
pull/494/merge
Miguel Veloso 6 years ago
committed by GitHub
parent
commit
f2a4f3ac2c
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 5 deletions
  1. +9
    -4
      src/Services/Ordering/Ordering.Domain/SeedWork/Entity.cs
  2. +1
    -1
      src/Services/Ordering/Ordering.Infrastructure/MediatorExtension.cs

+ 9
- 4
src/Services/Ordering/Ordering.Domain/SeedWork/Entity.cs View File

@ -21,17 +21,22 @@
}
private List<INotification> _domainEvents;
public List<INotification> DomainEvents => _domainEvents;
public IReadOnlyCollection<INotification> DomainEvents => _domainEvents?.AsReadOnly();
public void AddDomainEvent(INotification eventItem)
{
_domainEvents = _domainEvents ?? new List<INotification>();
_domainEvents.Add(eventItem);
}
public void RemoveDomainEvent(INotification eventItem)
{
if (_domainEvents is null) return;
_domainEvents.Remove(eventItem);
_domainEvents?.Remove(eventItem);
}
public void ClearDomainEvents()
{
_domainEvents?.Clear();
}
public bool IsTransient()


+ 1
- 1
src/Services/Ordering/Ordering.Infrastructure/MediatorExtension.cs View File

@ -19,7 +19,7 @@ namespace Ordering.Infrastructure
.ToList();
domainEntities.ToList()
.ForEach(entity => entity.Entity.DomainEvents.Clear());
.ForEach(entity => entity.Entity.ClearDomainEvents());
var tasks = domainEvents
.Select(async (domainEvent) => {


Loading…
Cancel
Save