Skip to content

Commit

Permalink
#247 Implement IHasConcurrencyStamp and IHasExtraProperties for aggre…
Browse files Browse the repository at this point in the history
…gate root.
  • Loading branch information
hikalkan committed Dec 11, 2018
1 parent 0d6a790 commit 58ef23d
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,31 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using Volo.Abp.Auditing;
using Volo.Abp.Data;

namespace Volo.Abp.Domain.Entities
{
[Serializable]
public abstract class AggregateRoot : Entity, IAggregateRoot, IGeneratesDomainEvents
public abstract class AggregateRoot : Entity,
IAggregateRoot,
IGeneratesDomainEvents,
IHasExtraProperties,
IHasConcurrencyStamp
{
public Dictionary<string, object> ExtraProperties { get; protected set; }

[DisableAuditing]
public string ConcurrencyStamp { get; set; }

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

protected AggregateRoot()
{
ExtraProperties = new Dictionary<string, object>();
}

protected virtual void AddLocalEvent(object eventData)
{
_localEvents.Add(eventData);
Expand All @@ -25,7 +41,7 @@ public virtual IEnumerable<object> GetLocalEvents()
return _localEvents;
}

public IEnumerable<object> GetDistributedEvents()
public virtual IEnumerable<object> GetDistributedEvents()
{
return _distributedEvents;
}
Expand All @@ -35,27 +51,36 @@ public virtual void ClearLocalEvents()
_localEvents.Clear();
}

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

[Serializable]
public abstract class AggregateRoot<TKey> : Entity<TKey>, IAggregateRoot<TKey>, IGeneratesDomainEvents
public abstract class AggregateRoot<TKey> : Entity<TKey>,
IAggregateRoot<TKey>,
IGeneratesDomainEvents,
IHasExtraProperties,
IHasConcurrencyStamp
{
public Dictionary<string, object> ExtraProperties { get; protected set; }

[DisableAuditing]
public string ConcurrencyStamp { get; set; }

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

protected AggregateRoot()
{

ExtraProperties = new Dictionary<string, object>();
}

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

ExtraProperties = new Dictionary<string, object>();
}

protected virtual void AddLocalEvent(object eventData)
Expand All @@ -73,7 +98,7 @@ public virtual IEnumerable<object> GetLocalEvents()
return _localEvents;
}

public IEnumerable<object> GetDistributedEvents()
public virtual IEnumerable<object> GetDistributedEvents()
{
return _distributedEvents;
}
Expand All @@ -83,7 +108,7 @@ public virtual void ClearLocalEvents()
_localEvents.Clear();
}

public void ClearDistributedEvents()
public virtual void ClearDistributedEvents()
{
_distributedEvents.Clear();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace Volo.Abp.Identity
/// <summary>
/// Represents a role in the identity system
/// </summary>
public class IdentityRole : AggregateRoot<Guid>, IHasConcurrencyStamp, IMultiTenant
public class IdentityRole : AggregateRoot<Guid>, IMultiTenant
{
public virtual Guid? TenantId { get; protected set; }

Expand All @@ -33,12 +33,6 @@ public class IdentityRole : AggregateRoot<Guid>, IHasConcurrencyStamp, IMultiTen
/// </summary>
public virtual ICollection<IdentityRoleClaim> Claims { get; protected set; }

/// <summary>
/// A random value that should change whenever a role is persisted to the store
/// </summary>
[DisableAuditing]
public virtual string ConcurrencyStamp { get; set; }

/// <summary>
/// A default role is automatically assigned to a new user
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,14 @@
using JetBrains.Annotations;
using Microsoft.AspNetCore.Identity;
using Volo.Abp.Auditing;
using Volo.Abp.Data;
using Volo.Abp.Domain.Entities;
using Volo.Abp.Domain.Entities.Auditing;
using Volo.Abp.Guids;
using Volo.Abp.ObjectMapping;
using Volo.Abp.Users;

namespace Volo.Abp.Identity
{
public class IdentityUser : FullAuditedAggregateRoot<Guid>, IHasConcurrencyStamp, IUser, IHasExtraProperties, IMapTo<UserEto>
public class IdentityUser : FullAuditedAggregateRoot<Guid>, IUser, IMapTo<UserEto>
{
public virtual Guid? TenantId { get; protected set; }

Expand Down Expand Up @@ -69,12 +67,6 @@ public class IdentityUser : FullAuditedAggregateRoot<Guid>, IHasConcurrencyStamp
[DisableAuditing]
public virtual string SecurityStamp { get; protected internal set; }

/// <summary>
/// A random value that must change whenever a user is persisted to the store
/// </summary>
[DisableAuditing]
public virtual string ConcurrencyStamp { get; set; }

/// <summary>
/// Gets or sets a telephone number for the user.
/// </summary>
Expand Down Expand Up @@ -133,8 +125,6 @@ public class IdentityUser : FullAuditedAggregateRoot<Guid>, IHasConcurrencyStamp
/// </summary>
public virtual ICollection<IdentityUserToken> Tokens { get; protected set; }

public Dictionary<string, object> ExtraProperties { get; protected set; }

protected IdentityUser()
{
ExtraProperties = new Dictionary<string, object>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ public static void ConfigureIdentity(
{
b.ToTable(options.TablePrefix + "Roles", options.Schema);

b.ConfigureExtraProperties();

b.Property(r => r.Name).IsRequired().HasMaxLength(IdentityRoleConsts.MaxNameLength);
b.Property(r => r.NormalizedName).IsRequired().HasMaxLength(IdentityRoleConsts.MaxNormalizedNameLength);
b.Property(r => r.IsDefault).HasColumnName(nameof(IdentityRole.IsDefault));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public static void Configure()
BsonClassMap.RegisterClassMap<IdentityRole>(map =>
{
map.AutoMap();
map.ConfigureExtraProperties();
});

BsonClassMap.RegisterClassMap<IdentityClaimType>(map =>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Microsoft.Extensions.DependencyInjection;
using MyCompanyName.MyProjectName.Permissions;
using MyCompanyName.MyProjectName.Permissions;
using Volo.Abp.Authorization.Permissions;
using Volo.Abp.AutoMapper;
using Volo.Abp.Identity;
Expand Down

0 comments on commit 58ef23d

Please sign in to comment.