Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce BasicAggregateRoot base class #4809

Merged
merged 1 commit into from Aug 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -9,9 +9,7 @@
namespace Volo.Abp.Domain.Entities
{
[Serializable]
public abstract class AggregateRoot : Entity,
IAggregateRoot,
IGeneratesDomainEvents,
public abstract class AggregateRoot : BasicAggregateRoot,
IHasExtraProperties,
IHasConcurrencyStamp
{
Expand All @@ -20,46 +18,13 @@ public abstract class AggregateRoot : Entity,
[DisableAuditing]
public virtual string ConcurrencyStamp { get; set; }

private readonly ICollection<object> _localEvents = new Collection<object>();
private readonly ICollection<object> _distributedEvents = new Collection<object>();

protected AggregateRoot()
{
ConcurrencyStamp = Guid.NewGuid().ToString("N");
ExtraProperties = new Dictionary<string, object>();
this.SetDefaultsForExtraProperties();
}

protected virtual void AddLocalEvent(object eventData)
{
_localEvents.Add(eventData);
}

protected virtual void AddDistributedEvent(object eventData)
{
_distributedEvents.Add(eventData);
}

public virtual IEnumerable<object> GetLocalEvents()
{
return _localEvents;
}

public virtual IEnumerable<object> GetDistributedEvents()
{
return _distributedEvents;
}

public virtual void ClearLocalEvents()
{
_localEvents.Clear();
}

public virtual void ClearDistributedEvents()
{
_distributedEvents.Clear();
}

public virtual IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{
return ExtensibleObjectValidator.GetValidationErrors(
Expand All @@ -70,9 +35,7 @@ public virtual IEnumerable<ValidationResult> Validate(ValidationContext validati
}

[Serializable]
public abstract class AggregateRoot<TKey> : Entity<TKey>,
IAggregateRoot<TKey>,
IGeneratesDomainEvents,
public abstract class AggregateRoot<TKey> : BasicAggregateRoot<TKey>,
IHasExtraProperties,
IHasConcurrencyStamp
{
Expand All @@ -81,9 +44,6 @@ public abstract class AggregateRoot<TKey> : Entity<TKey>,
[DisableAuditing]
public virtual string ConcurrencyStamp { get; set; }

private readonly ICollection<object> _localEvents = new Collection<object>();
private readonly ICollection<object> _distributedEvents = new Collection<object>();

protected AggregateRoot()
{
ConcurrencyStamp = Guid.NewGuid().ToString("N");
Expand All @@ -99,36 +59,6 @@ protected AggregateRoot(TKey id)
this.SetDefaultsForExtraProperties();
}

protected virtual void AddLocalEvent(object eventData)
{
_localEvents.Add(eventData);
}

protected virtual void AddDistributedEvent(object eventData)
{
_distributedEvents.Add(eventData);
}

public virtual IEnumerable<object> GetLocalEvents()
{
return _localEvents;
}

public virtual IEnumerable<object> GetDistributedEvents()
{
return _distributedEvents;
}

public virtual void ClearLocalEvents()
{
_localEvents.Clear();
}

public virtual void ClearDistributedEvents()
{
_distributedEvents.Clear();
}

public virtual IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{
return ExtensibleObjectValidator.GetValidationErrors(
Expand All @@ -137,4 +67,4 @@ public virtual IEnumerable<ValidationResult> Validate(ValidationContext validati
);
}
}
}
}
@@ -0,0 +1,95 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;

namespace Volo.Abp.Domain.Entities
{
[Serializable]
public abstract class BasicAggregateRoot : Entity,
IAggregateRoot,
IGeneratesDomainEvents
{
private readonly ICollection<object> _distributedEvents = new Collection<object>();
private readonly ICollection<object> _localEvents = new Collection<object>();

public virtual IEnumerable<object> GetLocalEvents()
{
return _localEvents;
}

public virtual IEnumerable<object> GetDistributedEvents()
{
return _distributedEvents;
}

public virtual void ClearLocalEvents()
{
_localEvents.Clear();
}

public virtual void ClearDistributedEvents()
{
_distributedEvents.Clear();
}

protected virtual void AddLocalEvent(object eventData)
{
_localEvents.Add(eventData);
}

protected virtual void AddDistributedEvent(object eventData)
{
_distributedEvents.Add(eventData);
}
}

[Serializable]
public abstract class BasicAggregateRoot<TKey> : Entity<TKey>,
IAggregateRoot<TKey>,
IGeneratesDomainEvents
{
private readonly ICollection<object> _distributedEvents = new Collection<object>();
private readonly ICollection<object> _localEvents = new Collection<object>();

protected BasicAggregateRoot()
{

}

protected BasicAggregateRoot(TKey id)
: base(id)
{

}

public virtual IEnumerable<object> GetLocalEvents()
{
return _localEvents;
}

public virtual IEnumerable<object> GetDistributedEvents()
{
return _distributedEvents;
}

public virtual void ClearLocalEvents()
{
_localEvents.Clear();
}

public virtual void ClearDistributedEvents()
{
_distributedEvents.Clear();
}

protected virtual void AddLocalEvent(object eventData)
{
_localEvents.Add(eventData);
}

protected virtual void AddDistributedEvent(object eventData)
{
_distributedEvents.Add(eventData);
}
}
}