chore 优化代码
This commit is contained in:
		| @ -1,8 +1,8 @@ | ||||
| using System; | ||||
| using System.Threading.Tasks; | ||||
| using KonSoft.Payment.Data; | ||||
| using Microsoft.EntityFrameworkCore; | ||||
| using Microsoft.Extensions.DependencyInjection; | ||||
| using KonSoft.Payment.Data; | ||||
| using Volo.Abp.DependencyInjection; | ||||
|  | ||||
| namespace KonSoft.Payment.EntityFrameworkCore; | ||||
| @ -31,4 +31,4 @@ public class EntityFrameworkCorePaymentDbSchemaMigrator | ||||
|             .Database | ||||
|             .MigrateAsync(); | ||||
|     } | ||||
| } | ||||
| } | ||||
| @ -23,40 +23,9 @@ public class PaymentDbContext : | ||||
|     IIdentityDbContext, | ||||
|     ITenantManagementDbContext | ||||
| { | ||||
|     /* Add DbSet properties for your Aggregate Roots / Entities here. */ | ||||
|  | ||||
|     #region Entities from the modules | ||||
|  | ||||
|     /* Notice: We only implemented IIdentityDbContext and ITenantManagementDbContext | ||||
|      * and replaced them for this DbContext. This allows you to perform JOIN | ||||
|      * queries for the entities of these modules over the repositories easily. You | ||||
|      * typically don't need that for other modules. But, if you need, you can | ||||
|      * implement the DbContext interface of the needed module and use ReplaceDbContext | ||||
|      * attribute just like IIdentityDbContext and ITenantManagementDbContext. | ||||
|      * | ||||
|      * More info: Replacing a DbContext of a module ensures that the related module | ||||
|      * uses this DbContext on runtime. Otherwise, it will use its own DbContext class. | ||||
|      */ | ||||
|  | ||||
|     //Identity | ||||
|     public DbSet<IdentityUser> Users { get; set; } | ||||
|     public DbSet<IdentityRole> Roles { get; set; } | ||||
|     public DbSet<IdentityClaimType> ClaimTypes { get; set; } | ||||
|     public DbSet<OrganizationUnit> OrganizationUnits { get; set; } | ||||
|     public DbSet<IdentitySecurityLog> SecurityLogs { get; set; } | ||||
|     public DbSet<IdentityLinkUser> LinkUsers { get; set; } | ||||
|     public DbSet<IdentityUserDelegation> UserDelegations { get; set; } | ||||
|     public DbSet<IdentitySession> Sessions { get; set; } | ||||
|     // Tenant Management | ||||
|     public DbSet<Tenant> Tenants { get; set; } | ||||
|     public DbSet<TenantConnectionString> TenantConnectionStrings { get; set; } | ||||
|  | ||||
|     #endregion | ||||
|  | ||||
|     public PaymentDbContext(DbContextOptions<PaymentDbContext> options) | ||||
|         : base(options) | ||||
|     { | ||||
|  | ||||
|     } | ||||
|  | ||||
|     protected override void OnModelCreating(ModelBuilder builder) | ||||
| @ -83,4 +52,35 @@ public class PaymentDbContext : | ||||
|         //    //... | ||||
|         //}); | ||||
|     } | ||||
| } | ||||
|     /* Add DbSet properties for your Aggregate Roots / Entities here. */ | ||||
|  | ||||
|     #region Entities from the modules | ||||
|  | ||||
|     /* Notice: We only implemented IIdentityDbContext and ITenantManagementDbContext | ||||
|      * and replaced them for this DbContext. This allows you to perform JOIN | ||||
|      * queries for the entities of these modules over the repositories easily. You | ||||
|      * typically don't need that for other modules. But, if you need, you can | ||||
|      * implement the DbContext interface of the needed module and use ReplaceDbContext | ||||
|      * attribute just like IIdentityDbContext and ITenantManagementDbContext. | ||||
|      * | ||||
|      * More info: Replacing a DbContext of a module ensures that the related module | ||||
|      * uses this DbContext on runtime. Otherwise, it will use its own DbContext class. | ||||
|      */ | ||||
|  | ||||
|     //Identity | ||||
|     public DbSet<IdentityUser> Users { get; set; } | ||||
|     public DbSet<IdentityRole> Roles { get; set; } | ||||
|     public DbSet<IdentityClaimType> ClaimTypes { get; set; } | ||||
|     public DbSet<OrganizationUnit> OrganizationUnits { get; set; } | ||||
|     public DbSet<IdentitySecurityLog> SecurityLogs { get; set; } | ||||
|     public DbSet<IdentityLinkUser> LinkUsers { get; set; } | ||||
|     public DbSet<IdentityUserDelegation> UserDelegations { get; set; } | ||||
|  | ||||
|     public DbSet<IdentitySession> Sessions { get; set; } | ||||
|  | ||||
|     // Tenant Management | ||||
|     public DbSet<Tenant> Tenants { get; set; } | ||||
|     public DbSet<TenantConnectionString> TenantConnectionStrings { get; set; } | ||||
|  | ||||
|     #endregion | ||||
| } | ||||
| @ -29,8 +29,8 @@ public class PaymentDbContextFactory : IDesignTimeDbContextFactory<PaymentDbCont | ||||
|     { | ||||
|         var builder = new ConfigurationBuilder() | ||||
|             .SetBasePath(Path.Combine(Directory.GetCurrentDirectory(), "../KonSoft.Payment.DbMigrator/")) | ||||
|             .AddJsonFile("appsettings.json", optional: false); | ||||
|             .AddJsonFile("appsettings.json", false); | ||||
|  | ||||
|         return builder.Build(); | ||||
|     } | ||||
| } | ||||
| } | ||||
| @ -1,13 +1,10 @@ | ||||
| using Microsoft.EntityFrameworkCore; | ||||
| using Volo.Abp.Identity; | ||||
| using Volo.Abp.ObjectExtending; | ||||
| using Volo.Abp.Threading; | ||||
| using Volo.Abp.Threading; | ||||
|  | ||||
| namespace KonSoft.Payment.EntityFrameworkCore; | ||||
|  | ||||
| public static class PaymentEfCoreEntityExtensionMappings | ||||
| { | ||||
|     private static readonly OneTimeRunner OneTimeRunner = new OneTimeRunner(); | ||||
|     private static readonly OneTimeRunner OneTimeRunner = new(); | ||||
|  | ||||
|     public static void Configure() | ||||
|     { | ||||
| @ -16,29 +13,29 @@ public static class PaymentEfCoreEntityExtensionMappings | ||||
|  | ||||
|         OneTimeRunner.Run(() => | ||||
|         { | ||||
|                 /* You can configure extra properties for the | ||||
|                  * entities defined in the modules used by your application. | ||||
|                  * | ||||
|                  * This class can be used to map these extra properties to table fields in the database. | ||||
|                  * | ||||
|                  * USE THIS CLASS ONLY TO CONFIGURE EF CORE RELATED MAPPING. | ||||
|                  * USE PaymentModuleExtensionConfigurator CLASS (in the Domain.Shared project) | ||||
|                  * FOR A HIGH LEVEL API TO DEFINE EXTRA PROPERTIES TO ENTITIES OF THE USED MODULES | ||||
|                  * | ||||
|                  * Example: Map a property to a table field: | ||||
|             /* You can configure extra properties for the | ||||
|              * entities defined in the modules used by your application. | ||||
|              * | ||||
|              * This class can be used to map these extra properties to table fields in the database. | ||||
|              * | ||||
|              * USE THIS CLASS ONLY TO CONFIGURE EF CORE RELATED MAPPING. | ||||
|              * USE PaymentModuleExtensionConfigurator CLASS (in the Domain.Shared project) | ||||
|              * FOR A HIGH LEVEL API TO DEFINE EXTRA PROPERTIES TO ENTITIES OF THE USED MODULES | ||||
|              * | ||||
|              * Example: Map a property to a table field: | ||||
|  | ||||
|                      ObjectExtensionManager.Instance | ||||
|                          .MapEfCoreProperty<IdentityUser, string>( | ||||
|                              "MyProperty", | ||||
|                              (entityBuilder, propertyBuilder) => | ||||
|                              { | ||||
|                                  propertyBuilder.HasMaxLength(128); | ||||
|                              } | ||||
|                          ); | ||||
|                  ObjectExtensionManager.Instance | ||||
|                      .MapEfCoreProperty<IdentityUser, string>( | ||||
|                          "MyProperty", | ||||
|                          (entityBuilder, propertyBuilder) => | ||||
|                          { | ||||
|                              propertyBuilder.HasMaxLength(128); | ||||
|                          } | ||||
|                      ); | ||||
|  | ||||
|                  * See the documentation for more: | ||||
|                  * https://docs.abp.io/en/abp/latest/Customizing-Application-Modules-Extending-Entities | ||||
|                  */ | ||||
|              * See the documentation for more: | ||||
|              * https://docs.abp.io/en/abp/latest/Customizing-Application-Modules-Extending-Entities | ||||
|              */ | ||||
|         }); | ||||
|     } | ||||
| } | ||||
| } | ||||
| @ -1,6 +1,5 @@ | ||||
| using System; | ||||
| using Microsoft.Extensions.DependencyInjection; | ||||
| using Volo.Abp.Uow; | ||||
| using Volo.Abp.AuditLogging.EntityFrameworkCore; | ||||
| using Volo.Abp.BackgroundJobs.EntityFrameworkCore; | ||||
| using Volo.Abp.EntityFrameworkCore; | ||||
| @ -26,7 +25,7 @@ namespace KonSoft.Payment.EntityFrameworkCore; | ||||
|     typeof(AbpAuditLoggingEntityFrameworkCoreModule), | ||||
|     typeof(AbpTenantManagementEntityFrameworkCoreModule), | ||||
|     typeof(AbpFeatureManagementEntityFrameworkCoreModule) | ||||
|     )] | ||||
| )] | ||||
| public class PaymentEntityFrameworkCoreModule : AbpModule | ||||
| { | ||||
|     public override void PreConfigureServices(ServiceConfigurationContext context) | ||||
| @ -41,17 +40,16 @@ public class PaymentEntityFrameworkCoreModule : AbpModule | ||||
|     { | ||||
|         context.Services.AddAbpDbContext<PaymentDbContext>(options => | ||||
|         { | ||||
|                 /* Remove "includeAllEntities: true" to create | ||||
|                  * default repositories only for aggregate roots */ | ||||
|             options.AddDefaultRepositories(includeAllEntities: true); | ||||
|             /* Remove "includeAllEntities: true" to create | ||||
|              * default repositories only for aggregate roots */ | ||||
|             options.AddDefaultRepositories(true); | ||||
|         }); | ||||
|  | ||||
|         Configure<AbpDbContextOptions>(options => | ||||
|         { | ||||
|                 /* The main point to change your DBMS. | ||||
|                  * See also PaymentMigrationsDbContextFactory for EF Core tooling. */ | ||||
|             /* The main point to change your DBMS. | ||||
|              * See also PaymentMigrationsDbContextFactory for EF Core tooling. */ | ||||
|             options.UseNpgsql(); | ||||
|         }); | ||||
|  | ||||
|     } | ||||
| } | ||||
| } | ||||
| @ -1,2 +1,3 @@ | ||||
| using System.Runtime.CompilerServices; | ||||
| [assembly:InternalsVisibleToAttribute("KonSoft.Payment.EntityFrameworkCore.Tests")] | ||||
|  | ||||
| [assembly: InternalsVisibleToAttribute("KonSoft.Payment.EntityFrameworkCore.Tests")] | ||||
		Reference in New Issue
	
	Block a user