Browse Source

#8887: Removed ModelBuilderConfigurationOptions for identity module

pull/10047/head
Halil İbrahim Kalkan 4 years ago
parent
commit
42fb3c8786
  1. 28
      docs/en/Best-Practices/Entity-Framework-Core-Integration.md
  2. 26
      docs/en/Best-Practices/MongoDB-Integration.md
  3. 37
      modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/IdentityDbContextModelBuilderExtensions.cs
  4. 18
      modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/IdentityModelBuilderConfigurationOptions.cs
  5. 25
      modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/AbpIdentityMongoDbContextExtensions.cs
  6. 13
      modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/IdentityMongoModelBuilderConfigurationOptions.cs

28
docs/en/Best-Practices/Entity-Framework-Core-Integration.md

@ -66,12 +66,7 @@ public static string Schema { get; set; } = AbpIdentityConsts.DefaultDbSchema;
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
builder.ConfigureIdentity(options =>
{
options.TablePrefix = TablePrefix;
options.Schema = Schema;
});
builder.ConfigureIdentity();
}
````
@ -80,25 +75,19 @@ protected override void OnModelCreating(ModelBuilder builder)
````C#
public static class IdentityDbContextModelBuilderExtensions
{
public static void ConfigureIdentity(
[NotNull] this ModelBuilder builder,
Action<IdentityModelBuilderConfigurationOptions> optionsAction = null)
{
Check.NotNull(builder, nameof(builder));
var options = new IdentityModelBuilderConfigurationOptions();
optionsAction?.Invoke(options);
builder.Entity<IdentityUser>(b =>
{
b.ToTable(options.TablePrefix + "Users", options.Schema);
b.ToTable(AbpIdentityDbProperties.DbTablePrefix + "Users", AbpIdentityDbProperties.DbSchema);
b.ConfigureByConvention();
//code omitted for brevity
});
builder.Entity<IdentityUserClaim>(b =>
{
b.ToTable(options.TablePrefix + "UserClaims", options.Schema);
b.ToTable(AbpIdentityDbProperties.DbTablePrefix + "UserClaims", AbpIdentityDbProperties.DbSchema);
b.ConfigureByConvention();
//code omitted for brevity
});
@ -109,17 +98,6 @@ public static class IdentityDbContextModelBuilderExtensions
````
* **Do** call `b.ConfigureByConvention();` for each entity mapping (as shown above).
* **Do** create a **configuration options** class by inheriting from the `AbpModelBuilderConfigurationOptions`. Example:
````C#
public class IdentityModelBuilderConfigurationOptions : AbpModelBuilderConfigurationOptions
{
public IdentityModelBuilderConfigurationOptions()
: base(AbpIdentityConsts.DefaultDbTablePrefix, AbpIdentityConsts.DefaultDbSchema)
{
}
}
````
### Repository Implementation

26
docs/en/Best-Practices/MongoDB-Integration.md

@ -55,10 +55,7 @@ protected override void CreateModel(IMongoModelBuilder modelBuilder)
{
base.CreateModel(modelBuilder);
modelBuilder.ConfigureIdentity(options =>
{
options.CollectionPrefix = CollectionPrefix;
});
modelBuilder.ConfigureIdentity();
}
```
@ -73,36 +70,19 @@ public static class AbpIdentityMongoDbContextExtensions
{
Check.NotNull(builder, nameof(builder));
var options = new IdentityMongoModelBuilderConfigurationOptions();
optionsAction?.Invoke(options);
builder.Entity<IdentityUser>(b =>
{
b.CollectionName = options.CollectionPrefix + "Users";
b.CollectionName = AbpIdentityDbProperties.DbTablePrefix + "Users";
});
builder.Entity<IdentityRole>(b =>
{
b.CollectionName = options.CollectionPrefix + "Roles";
b.CollectionName = AbpIdentityDbProperties.DbTablePrefix + "Roles";
});
}
}
```
- **Do** create a **configuration options** class by inheriting from the `AbpMongoModelBuilderConfigurationOptions`. Example:
```c#
public class IdentityMongoModelBuilderConfigurationOptions
: AbpMongoModelBuilderConfigurationOptions
{
public IdentityMongoModelBuilderConfigurationOptions()
: base(AbpIdentityConsts.DefaultDbTablePrefix)
{
}
}
```
### Repository Implementation
- **Do** **inherit** the repository from the `MongoDbRepository<TMongoDbContext, TEntity, TKey>` class and implement the corresponding repository interface. Example:

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

@ -8,22 +8,13 @@ namespace Volo.Abp.Identity.EntityFrameworkCore
{
public static class IdentityDbContextModelBuilderExtensions
{
public static void ConfigureIdentity(
[NotNull] this ModelBuilder builder,
[CanBeNull] Action<IdentityModelBuilderConfigurationOptions> optionsAction = null)
public static void ConfigureIdentity([NotNull] this ModelBuilder builder)
{
Check.NotNull(builder, nameof(builder));
var options = new IdentityModelBuilderConfigurationOptions(
AbpIdentityDbProperties.DbTablePrefix,
AbpIdentityDbProperties.DbSchema
);
optionsAction?.Invoke(options);
builder.Entity<IdentityUser>(b =>
{
b.ToTable(options.TablePrefix + "Users", options.Schema);
b.ToTable(AbpIdentityDbProperties.DbTablePrefix + "Users", AbpIdentityDbProperties.DbSchema);
b.ConfigureByConvention();
b.ConfigureAbpUser();
@ -66,7 +57,7 @@ namespace Volo.Abp.Identity.EntityFrameworkCore
builder.Entity<IdentityUserClaim>(b =>
{
b.ToTable(options.TablePrefix + "UserClaims", options.Schema);
b.ToTable(AbpIdentityDbProperties.DbTablePrefix + "UserClaims", AbpIdentityDbProperties.DbSchema);
b.ConfigureByConvention();
@ -82,7 +73,7 @@ namespace Volo.Abp.Identity.EntityFrameworkCore
builder.Entity<IdentityUserRole>(b =>
{
b.ToTable(options.TablePrefix + "UserRoles", options.Schema);
b.ToTable(AbpIdentityDbProperties.DbTablePrefix + "UserRoles", AbpIdentityDbProperties.DbSchema);
b.ConfigureByConvention();
@ -98,7 +89,7 @@ namespace Volo.Abp.Identity.EntityFrameworkCore
builder.Entity<IdentityUserLogin>(b =>
{
b.ToTable(options.TablePrefix + "UserLogins", options.Schema);
b.ToTable(AbpIdentityDbProperties.DbTablePrefix + "UserLogins", AbpIdentityDbProperties.DbSchema);
b.ConfigureByConvention();
@ -118,7 +109,7 @@ namespace Volo.Abp.Identity.EntityFrameworkCore
builder.Entity<IdentityUserToken>(b =>
{
b.ToTable(options.TablePrefix + "UserTokens", options.Schema);
b.ToTable(AbpIdentityDbProperties.DbTablePrefix + "UserTokens", AbpIdentityDbProperties.DbSchema);
b.ConfigureByConvention();
@ -133,7 +124,7 @@ namespace Volo.Abp.Identity.EntityFrameworkCore
builder.Entity<IdentityRole>(b =>
{
b.ToTable(options.TablePrefix + "Roles", options.Schema);
b.ToTable(AbpIdentityDbProperties.DbTablePrefix + "Roles", AbpIdentityDbProperties.DbSchema);
b.ConfigureByConvention();
@ -152,7 +143,7 @@ namespace Volo.Abp.Identity.EntityFrameworkCore
builder.Entity<IdentityRoleClaim>(b =>
{
b.ToTable(options.TablePrefix + "RoleClaims", options.Schema);
b.ToTable(AbpIdentityDbProperties.DbTablePrefix + "RoleClaims", AbpIdentityDbProperties.DbSchema);
b.ConfigureByConvention();
@ -170,7 +161,7 @@ namespace Volo.Abp.Identity.EntityFrameworkCore
{
builder.Entity<IdentityClaimType>(b =>
{
b.ToTable(options.TablePrefix + "ClaimTypes", options.Schema);
b.ToTable(AbpIdentityDbProperties.DbTablePrefix + "ClaimTypes", AbpIdentityDbProperties.DbSchema);
b.ConfigureByConvention();
@ -186,7 +177,7 @@ namespace Volo.Abp.Identity.EntityFrameworkCore
builder.Entity<OrganizationUnit>(b =>
{
b.ToTable(options.TablePrefix + "OrganizationUnits", options.Schema);
b.ToTable(AbpIdentityDbProperties.DbTablePrefix + "OrganizationUnits", AbpIdentityDbProperties.DbSchema);
b.ConfigureByConvention();
@ -205,7 +196,7 @@ namespace Volo.Abp.Identity.EntityFrameworkCore
builder.Entity<OrganizationUnitRole>(b =>
{
b.ToTable(options.TablePrefix + "OrganizationUnitRoles", options.Schema);
b.ToTable(AbpIdentityDbProperties.DbTablePrefix + "OrganizationUnitRoles", AbpIdentityDbProperties.DbSchema);
b.ConfigureByConvention();
@ -220,7 +211,7 @@ namespace Volo.Abp.Identity.EntityFrameworkCore
builder.Entity<IdentityUserOrganizationUnit>(b =>
{
b.ToTable(options.TablePrefix + "UserOrganizationUnits", options.Schema);
b.ToTable(AbpIdentityDbProperties.DbTablePrefix + "UserOrganizationUnits", AbpIdentityDbProperties.DbSchema);
b.ConfigureByConvention();
@ -235,7 +226,7 @@ namespace Volo.Abp.Identity.EntityFrameworkCore
builder.Entity<IdentitySecurityLog>(b =>
{
b.ToTable(options.TablePrefix + "SecurityLogs", options.Schema);
b.ToTable(AbpIdentityDbProperties.DbTablePrefix + "SecurityLogs", AbpIdentityDbProperties.DbSchema);
b.ConfigureByConvention();
@ -264,7 +255,7 @@ namespace Volo.Abp.Identity.EntityFrameworkCore
{
builder.Entity<IdentityLinkUser>(b =>
{
b.ToTable(options.TablePrefix + "LinkUsers", options.Schema);
b.ToTable(AbpIdentityDbProperties.DbTablePrefix + "LinkUsers", AbpIdentityDbProperties.DbSchema);
b.ConfigureByConvention();

18
modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/IdentityModelBuilderConfigurationOptions.cs

@ -1,18 +0,0 @@
using JetBrains.Annotations;
using Volo.Abp.EntityFrameworkCore.Modeling;
namespace Volo.Abp.Identity.EntityFrameworkCore
{
public class IdentityModelBuilderConfigurationOptions : AbpModelBuilderConfigurationOptions
{
public IdentityModelBuilderConfigurationOptions(
[NotNull] string tablePrefix,
[CanBeNull] string schema)
: base(
tablePrefix,
schema)
{
}
}
}

25
modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/AbpIdentityMongoDbContextExtensions.cs

@ -1,50 +1,41 @@
using System;
using Volo.Abp.MongoDB;
using Volo.Abp.MongoDB;
namespace Volo.Abp.Identity.MongoDB
{
public static class AbpIdentityMongoDbContextExtensions
{
public static void ConfigureIdentity(
this IMongoModelBuilder builder,
Action<IdentityMongoModelBuilderConfigurationOptions> optionsAction = null)
public static void ConfigureIdentity(this IMongoModelBuilder builder)
{
Check.NotNull(builder, nameof(builder));
var options = new IdentityMongoModelBuilderConfigurationOptions(
AbpIdentityDbProperties.DbTablePrefix
);
optionsAction?.Invoke(options);
builder.Entity<IdentityUser>(b =>
{
b.CollectionName = options.CollectionPrefix + "Users";
b.CollectionName = AbpIdentityDbProperties.DbTablePrefix + "Users";
});
builder.Entity<IdentityRole>(b =>
{
b.CollectionName = options.CollectionPrefix + "Roles";
b.CollectionName = AbpIdentityDbProperties.DbTablePrefix + "Roles";
});
builder.Entity<IdentityClaimType>(b =>
{
b.CollectionName = options.CollectionPrefix + "ClaimTypes";
b.CollectionName = AbpIdentityDbProperties.DbTablePrefix + "ClaimTypes";
});
builder.Entity<OrganizationUnit>(b =>
{
b.CollectionName = options.CollectionPrefix + "OrganizationUnits";
b.CollectionName = AbpIdentityDbProperties.DbTablePrefix + "OrganizationUnits";
});
builder.Entity<IdentitySecurityLog>(b =>
{
b.CollectionName = options.CollectionPrefix + "SecurityLogs";
b.CollectionName = AbpIdentityDbProperties.DbTablePrefix + "SecurityLogs";
});
builder.Entity<IdentityLinkUser>(b =>
{
b.CollectionName = options.CollectionPrefix + "LinkUsers";
b.CollectionName = AbpIdentityDbProperties.DbTablePrefix + "LinkUsers";
});
}
}

13
modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/IdentityMongoModelBuilderConfigurationOptions.cs

@ -1,13 +0,0 @@
using JetBrains.Annotations;
using Volo.Abp.MongoDB;
namespace Volo.Abp.Identity.MongoDB
{
public class IdentityMongoModelBuilderConfigurationOptions : AbpMongoModelBuilderConfigurationOptions
{
public IdentityMongoModelBuilderConfigurationOptions([NotNull] string collectionPrefix = "")
: base(collectionPrefix)
{
}
}
}
Loading…
Cancel
Save