From 58ef23db03f4d663dbb71e53048bbc6b0152ecb9 Mon Sep 17 00:00:00 2001 From: Halil ibrahim Kalkan Date: Tue, 11 Dec 2018 16:54:23 +0300 Subject: [PATCH] #247 Implement IHasConcurrencyStamp and IHasExtraProperties for aggregate root. --- .../Volo/Abp/Domain/Entities/AggregateRoot.cs | 41 +++++++++++++++---- .../Volo/Abp/Identity/IdentityRole.cs | 8 +--- .../Volo/Abp/Identity/IdentityUser.cs | 12 +----- ...IdentityDbContextModelBuilderExtensions.cs | 2 + .../MongoDB/AbpIdentityBsonClassMap.cs | 1 + .../MyProjectNameApplicationModule.cs | 3 +- 6 files changed, 39 insertions(+), 28 deletions(-) diff --git a/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/AggregateRoot.cs b/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/AggregateRoot.cs index 2916b7de3be..35216724452 100644 --- a/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/AggregateRoot.cs +++ b/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/AggregateRoot.cs @@ -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 ExtraProperties { get; protected set; } + + [DisableAuditing] + public string ConcurrencyStamp { get; set; } + private readonly ICollection _localEvents = new Collection(); private readonly ICollection _distributedEvents = new Collection(); + protected AggregateRoot() + { + ExtraProperties = new Dictionary(); + } + protected virtual void AddLocalEvent(object eventData) { _localEvents.Add(eventData); @@ -25,7 +41,7 @@ public virtual IEnumerable GetLocalEvents() return _localEvents; } - public IEnumerable GetDistributedEvents() + public virtual IEnumerable GetDistributedEvents() { return _distributedEvents; } @@ -35,27 +51,36 @@ public virtual void ClearLocalEvents() _localEvents.Clear(); } - public void ClearDistributedEvents() + public virtual void ClearDistributedEvents() { _distributedEvents.Clear(); } } [Serializable] - public abstract class AggregateRoot : Entity, IAggregateRoot, IGeneratesDomainEvents + public abstract class AggregateRoot : Entity, + IAggregateRoot, + IGeneratesDomainEvents, + IHasExtraProperties, + IHasConcurrencyStamp { + public Dictionary ExtraProperties { get; protected set; } + + [DisableAuditing] + public string ConcurrencyStamp { get; set; } + private readonly ICollection _localEvents = new Collection(); private readonly ICollection _distributedEvents = new Collection(); protected AggregateRoot() { - + ExtraProperties = new Dictionary(); } protected AggregateRoot(TKey id) : base(id) { - + ExtraProperties = new Dictionary(); } protected virtual void AddLocalEvent(object eventData) @@ -73,7 +98,7 @@ public virtual IEnumerable GetLocalEvents() return _localEvents; } - public IEnumerable GetDistributedEvents() + public virtual IEnumerable GetDistributedEvents() { return _distributedEvents; } @@ -83,7 +108,7 @@ public virtual void ClearLocalEvents() _localEvents.Clear(); } - public void ClearDistributedEvents() + public virtual void ClearDistributedEvents() { _distributedEvents.Clear(); } diff --git a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityRole.cs b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityRole.cs index 8d87bf8788e..1b2a8494387 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityRole.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityRole.cs @@ -13,7 +13,7 @@ namespace Volo.Abp.Identity /// /// Represents a role in the identity system /// - public class IdentityRole : AggregateRoot, IHasConcurrencyStamp, IMultiTenant + public class IdentityRole : AggregateRoot, IMultiTenant { public virtual Guid? TenantId { get; protected set; } @@ -33,12 +33,6 @@ public class IdentityRole : AggregateRoot, IHasConcurrencyStamp, IMultiTen /// public virtual ICollection Claims { get; protected set; } - /// - /// A random value that should change whenever a role is persisted to the store - /// - [DisableAuditing] - public virtual string ConcurrencyStamp { get; set; } - /// /// A default role is automatically assigned to a new user /// diff --git a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUser.cs b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUser.cs index 449561bc274..38c19045323 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUser.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUser.cs @@ -6,8 +6,6 @@ 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; @@ -15,7 +13,7 @@ namespace Volo.Abp.Identity { - public class IdentityUser : FullAuditedAggregateRoot, IHasConcurrencyStamp, IUser, IHasExtraProperties, IMapTo + public class IdentityUser : FullAuditedAggregateRoot, IUser, IMapTo { public virtual Guid? TenantId { get; protected set; } @@ -69,12 +67,6 @@ public class IdentityUser : FullAuditedAggregateRoot, IHasConcurrencyStamp [DisableAuditing] public virtual string SecurityStamp { get; protected internal set; } - /// - /// A random value that must change whenever a user is persisted to the store - /// - [DisableAuditing] - public virtual string ConcurrencyStamp { get; set; } - /// /// Gets or sets a telephone number for the user. /// @@ -133,8 +125,6 @@ public class IdentityUser : FullAuditedAggregateRoot, IHasConcurrencyStamp /// public virtual ICollection Tokens { get; protected set; } - public Dictionary ExtraProperties { get; protected set; } - protected IdentityUser() { ExtraProperties = new Dictionary(); diff --git a/modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/IdentityDbContextModelBuilderExtensions.cs b/modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/IdentityDbContextModelBuilderExtensions.cs index af5cfd19e89..a0ffadea8cb 100644 --- a/modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/IdentityDbContextModelBuilderExtensions.cs +++ b/modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/IdentityDbContextModelBuilderExtensions.cs @@ -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)); diff --git a/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/AbpIdentityBsonClassMap.cs b/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/AbpIdentityBsonClassMap.cs index 5d380afde92..6bd6ff8623d 100644 --- a/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/AbpIdentityBsonClassMap.cs +++ b/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/AbpIdentityBsonClassMap.cs @@ -21,6 +21,7 @@ public static void Configure() BsonClassMap.RegisterClassMap(map => { map.AutoMap(); + map.ConfigureExtraProperties(); }); BsonClassMap.RegisterClassMap(map => diff --git a/templates/mvc/src/MyCompanyName.MyProjectName.Application/MyProjectNameApplicationModule.cs b/templates/mvc/src/MyCompanyName.MyProjectName.Application/MyProjectNameApplicationModule.cs index 464e982a1ee..644b18ac341 100644 --- a/templates/mvc/src/MyCompanyName.MyProjectName.Application/MyProjectNameApplicationModule.cs +++ b/templates/mvc/src/MyCompanyName.MyProjectName.Application/MyProjectNameApplicationModule.cs @@ -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;