Browse Source

#247 Implement IHasConcurrencyStamp and IHasExtraProperties for aggregate root.

pull/640/head
Halil ibrahim Kalkan 7 years ago
parent
commit
58ef23db03
  1. 41
      framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/AggregateRoot.cs
  2. 8
      modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityRole.cs
  3. 12
      modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUser.cs
  4. 2
      modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/IdentityDbContextModelBuilderExtensions.cs
  5. 1
      modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/AbpIdentityBsonClassMap.cs
  6. 3
      templates/mvc/src/MyCompanyName.MyProjectName.Application/MyProjectNameApplicationModule.cs

41
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<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);
@ -25,7 +41,7 @@ namespace Volo.Abp.Domain.Entities
return _localEvents;
}
public IEnumerable<object> GetDistributedEvents()
public virtual IEnumerable<object> GetDistributedEvents()
{
return _distributedEvents;
}
@ -35,27 +51,36 @@ namespace Volo.Abp.Domain.Entities
_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)
@ -73,7 +98,7 @@ namespace Volo.Abp.Domain.Entities
return _localEvents;
}
public IEnumerable<object> GetDistributedEvents()
public virtual IEnumerable<object> GetDistributedEvents()
{
return _distributedEvents;
}
@ -83,7 +108,7 @@ namespace Volo.Abp.Domain.Entities
_localEvents.Clear();
}
public void ClearDistributedEvents()
public virtual void ClearDistributedEvents()
{
_distributedEvents.Clear();
}

8
modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityRole.cs

@ -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; }
@ -33,12 +33,6 @@ namespace Volo.Abp.Identity
/// </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>

12
modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUser.cs

@ -6,8 +6,6 @@ using System.Security.Claims;
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 @@ 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; }
@ -69,12 +67,6 @@ namespace Volo.Abp.Identity
[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>
@ -133,8 +125,6 @@ namespace Volo.Abp.Identity
/// </summary>
public virtual ICollection<IdentityUserToken> Tokens { get; protected set; }
public Dictionary<string, object> ExtraProperties { get; protected set; }
protected IdentityUser()
{
ExtraProperties = new Dictionary<string, object>();

2
modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/IdentityDbContextModelBuilderExtensions.cs

@ -95,6 +95,8 @@ namespace Volo.Abp.Identity.EntityFrameworkCore
{
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));

1
modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/AbpIdentityBsonClassMap.cs

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

3
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;

Loading…
Cancel
Save