#247 Implement IHasConcurrencyStamp and IHasExtraProperties for aggregate root.

pull/640/head
Halil ibrahim Kalkan 7 years ago
parent 0d6a790569
commit 58ef23db03

@ -1,15 +1,31 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using Volo.Abp.Auditing;
using Volo.Abp.Data;
namespace Volo.Abp.Domain.Entities namespace Volo.Abp.Domain.Entities
{ {
[Serializable] [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> _localEvents = new Collection<object>();
private readonly ICollection<object> _distributedEvents = new Collection<object>(); private readonly ICollection<object> _distributedEvents = new Collection<object>();
protected AggregateRoot()
{
ExtraProperties = new Dictionary<string, object>();
}
protected virtual void AddLocalEvent(object eventData) protected virtual void AddLocalEvent(object eventData)
{ {
_localEvents.Add(eventData); _localEvents.Add(eventData);
@ -25,7 +41,7 @@ namespace Volo.Abp.Domain.Entities
return _localEvents; return _localEvents;
} }
public IEnumerable<object> GetDistributedEvents() public virtual IEnumerable<object> GetDistributedEvents()
{ {
return _distributedEvents; return _distributedEvents;
} }
@ -35,27 +51,36 @@ namespace Volo.Abp.Domain.Entities
_localEvents.Clear(); _localEvents.Clear();
} }
public void ClearDistributedEvents() public virtual void ClearDistributedEvents()
{ {
_distributedEvents.Clear(); _distributedEvents.Clear();
} }
} }
[Serializable] [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> _localEvents = new Collection<object>();
private readonly ICollection<object> _distributedEvents = new Collection<object>(); private readonly ICollection<object> _distributedEvents = new Collection<object>();
protected AggregateRoot() protected AggregateRoot()
{ {
ExtraProperties = new Dictionary<string, object>();
} }
protected AggregateRoot(TKey id) protected AggregateRoot(TKey id)
: base(id) : base(id)
{ {
ExtraProperties = new Dictionary<string, object>();
} }
protected virtual void AddLocalEvent(object eventData) protected virtual void AddLocalEvent(object eventData)
@ -73,7 +98,7 @@ namespace Volo.Abp.Domain.Entities
return _localEvents; return _localEvents;
} }
public IEnumerable<object> GetDistributedEvents() public virtual IEnumerable<object> GetDistributedEvents()
{ {
return _distributedEvents; return _distributedEvents;
} }
@ -83,7 +108,7 @@ namespace Volo.Abp.Domain.Entities
_localEvents.Clear(); _localEvents.Clear();
} }
public void ClearDistributedEvents() public virtual void ClearDistributedEvents()
{ {
_distributedEvents.Clear(); _distributedEvents.Clear();
} }

@ -13,7 +13,7 @@ namespace Volo.Abp.Identity
/// <summary> /// <summary>
/// Represents a role in the identity system /// Represents a role in the identity system
/// </summary> /// </summary>
public class IdentityRole : AggregateRoot<Guid>, IHasConcurrencyStamp, IMultiTenant public class IdentityRole : AggregateRoot<Guid>, IMultiTenant
{ {
public virtual Guid? TenantId { get; protected set; } public virtual Guid? TenantId { get; protected set; }
@ -33,12 +33,6 @@ namespace Volo.Abp.Identity
/// </summary> /// </summary>
public virtual ICollection<IdentityRoleClaim> Claims { get; protected set; } 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> /// <summary>
/// A default role is automatically assigned to a new user /// A default role is automatically assigned to a new user
/// </summary> /// </summary>

@ -6,8 +6,6 @@ using System.Security.Claims;
using JetBrains.Annotations; using JetBrains.Annotations;
using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity;
using Volo.Abp.Auditing; using Volo.Abp.Auditing;
using Volo.Abp.Data;
using Volo.Abp.Domain.Entities;
using Volo.Abp.Domain.Entities.Auditing; using Volo.Abp.Domain.Entities.Auditing;
using Volo.Abp.Guids; using Volo.Abp.Guids;
using Volo.Abp.ObjectMapping; using Volo.Abp.ObjectMapping;
@ -15,7 +13,7 @@ using Volo.Abp.Users;
namespace Volo.Abp.Identity 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; } public virtual Guid? TenantId { get; protected set; }
@ -69,12 +67,6 @@ namespace Volo.Abp.Identity
[DisableAuditing] [DisableAuditing]
public virtual string SecurityStamp { get; protected internal set; } 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> /// <summary>
/// Gets or sets a telephone number for the user. /// Gets or sets a telephone number for the user.
/// </summary> /// </summary>
@ -133,8 +125,6 @@ namespace Volo.Abp.Identity
/// </summary> /// </summary>
public virtual ICollection<IdentityUserToken> Tokens { get; protected set; } public virtual ICollection<IdentityUserToken> Tokens { get; protected set; }
public Dictionary<string, object> ExtraProperties { get; protected set; }
protected IdentityUser() protected IdentityUser()
{ {
ExtraProperties = new Dictionary<string, object>(); ExtraProperties = new Dictionary<string, object>();

@ -95,6 +95,8 @@ namespace Volo.Abp.Identity.EntityFrameworkCore
{ {
b.ToTable(options.TablePrefix + "Roles", options.Schema); b.ToTable(options.TablePrefix + "Roles", options.Schema);
b.ConfigureExtraProperties();
b.Property(r => r.Name).IsRequired().HasMaxLength(IdentityRoleConsts.MaxNameLength); b.Property(r => r.Name).IsRequired().HasMaxLength(IdentityRoleConsts.MaxNameLength);
b.Property(r => r.NormalizedName).IsRequired().HasMaxLength(IdentityRoleConsts.MaxNormalizedNameLength); b.Property(r => r.NormalizedName).IsRequired().HasMaxLength(IdentityRoleConsts.MaxNormalizedNameLength);
b.Property(r => r.IsDefault).HasColumnName(nameof(IdentityRole.IsDefault)); b.Property(r => r.IsDefault).HasColumnName(nameof(IdentityRole.IsDefault));

@ -21,6 +21,7 @@ namespace Volo.Abp.Identity.MongoDB
BsonClassMap.RegisterClassMap<IdentityRole>(map => BsonClassMap.RegisterClassMap<IdentityRole>(map =>
{ {
map.AutoMap(); map.AutoMap();
map.ConfigureExtraProperties();
}); });
BsonClassMap.RegisterClassMap<IdentityClaimType>(map => BsonClassMap.RegisterClassMap<IdentityClaimType>(map =>

@ -1,5 +1,4 @@
using Microsoft.Extensions.DependencyInjection; using MyCompanyName.MyProjectName.Permissions;
using MyCompanyName.MyProjectName.Permissions;
using Volo.Abp.Authorization.Permissions; using Volo.Abp.Authorization.Permissions;
using Volo.Abp.AutoMapper; using Volo.Abp.AutoMapper;
using Volo.Abp.Identity; using Volo.Abp.Identity;

Loading…
Cancel
Save