Merge pull request #561 from Alexbits/hotfix/EntityEncapsulationFix

Improved encapsulation of DomainEvents collection in Entity class
This commit is contained in:
Miguel Veloso 2018-03-27 19:43:31 +01:00 committed by GitHub
commit f2a4f3ac2c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 5 deletions

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()

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) => {