Browse Source

Merge pull request #24533 from abpframework/BasicAggregateRoot_Events

Refactor BasicAggregateRoot to use nullable collections for distributed and local events
pull/24535/head
Halil İbrahim Kalkan 1 month ago
committed by GitHub
parent
commit
d2afff914c
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 28
      framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/BasicAggregateRoot.cs

28
framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/BasicAggregateRoot.cs

@ -10,36 +10,38 @@ public abstract class BasicAggregateRoot : Entity,
IAggregateRoot,
IGeneratesDomainEvents
{
private readonly ICollection<DomainEventRecord> _distributedEvents = new Collection<DomainEventRecord>();
private readonly ICollection<DomainEventRecord> _localEvents = new Collection<DomainEventRecord>();
private ICollection<DomainEventRecord>? _distributedEvents;
private ICollection<DomainEventRecord>? _localEvents;
public virtual IEnumerable<DomainEventRecord> GetLocalEvents()
{
return _localEvents;
return _localEvents ?? Array.Empty<DomainEventRecord>();
}
public virtual IEnumerable<DomainEventRecord> GetDistributedEvents()
{
return _distributedEvents;
return _distributedEvents ?? Array.Empty<DomainEventRecord>();
}
public virtual void ClearLocalEvents()
{
_localEvents.Clear();
_localEvents?.Clear();
}
public virtual void ClearDistributedEvents()
{
_distributedEvents.Clear();
_distributedEvents?.Clear();
}
protected virtual void AddLocalEvent(object eventData)
{
_localEvents ??= new Collection<DomainEventRecord>();
_localEvents.Add(new DomainEventRecord(eventData, EventOrderGenerator.GetNext()));
}
protected virtual void AddDistributedEvent(object eventData)
{
_distributedEvents ??= new Collection<DomainEventRecord>();
_distributedEvents.Add(new DomainEventRecord(eventData, EventOrderGenerator.GetNext()));
}
}
@ -49,8 +51,8 @@ public abstract class BasicAggregateRoot<TKey> : Entity<TKey>,
IAggregateRoot<TKey>,
IGeneratesDomainEvents
{
private readonly ICollection<DomainEventRecord> _distributedEvents = new Collection<DomainEventRecord>();
private readonly ICollection<DomainEventRecord> _localEvents = new Collection<DomainEventRecord>();
private ICollection<DomainEventRecord>? _distributedEvents;
private ICollection<DomainEventRecord>? _localEvents;
protected BasicAggregateRoot()
{
@ -65,31 +67,33 @@ public abstract class BasicAggregateRoot<TKey> : Entity<TKey>,
public virtual IEnumerable<DomainEventRecord> GetLocalEvents()
{
return _localEvents;
return _localEvents ?? Array.Empty<DomainEventRecord>();
}
public virtual IEnumerable<DomainEventRecord> GetDistributedEvents()
{
return _distributedEvents;
return _distributedEvents ?? Array.Empty<DomainEventRecord>();
}
public virtual void ClearLocalEvents()
{
_localEvents.Clear();
_localEvents?.Clear();
}
public virtual void ClearDistributedEvents()
{
_distributedEvents.Clear();
_distributedEvents?.Clear();
}
protected virtual void AddLocalEvent(object eventData)
{
_localEvents ??= new Collection<DomainEventRecord>();
_localEvents.Add(new DomainEventRecord(eventData, EventOrderGenerator.GetNext()));
}
protected virtual void AddDistributedEvent(object eventData)
{
_distributedEvents ??= new Collection<DomainEventRecord>();
_distributedEvents.Add(new DomainEventRecord(eventData, EventOrderGenerator.GetNext()));
}
}

Loading…
Cancel
Save