chore 优化代码

This commit is contained in:
2025-10-16 10:30:51 +08:00
parent f1c609b4be
commit 1f5bc3e971
367 changed files with 2705 additions and 3083 deletions

View File

@ -17,4 +17,4 @@ public class TenantManagementPermissionDefinitionProvider : PermissionDefinition
{
return LocalizableString.Create<TenantManagementResource>(name);
}
}
}

View File

@ -6,4 +6,4 @@ public static class TenantManagementPermissions
//Add your own permission names. Example:
//public const string MyPermission1 = GroupName + ".MyPermission1";
}
}

View File

@ -25,4 +25,4 @@ public class TenantManagementApplicationContractsModule : AbpModule
{
TenantManagementDtoExtensions.Configure();
}
}
}

View File

@ -1,28 +1,26 @@
using Volo.Abp.Identity;
using Volo.Abp.ObjectExtending;
using Volo.Abp.Threading;
using Volo.Abp.Threading;
namespace KonSoft.TenantManagement;
public static class TenantManagementDtoExtensions
{
private static readonly OneTimeRunner OneTimeRunner = new OneTimeRunner();
private static readonly OneTimeRunner OneTimeRunner = new();
public static void Configure()
{
OneTimeRunner.Run(() =>
{
/* You can add extension properties to DTOs
* defined in the depended modules.
*
* Example:
*
* ObjectExtensionManager.Instance
* .AddOrUpdateProperty<IdentityRoleDto, string>("Title");
*
* See the documentation for more:
* https://docs.abp.io/en/abp/latest/Object-Extensions
*/
/* You can add extension properties to DTOs
* defined in the depended modules.
*
* Example:
*
* ObjectExtensionManager.Instance
* .AddOrUpdateProperty<IdentityRoleDto, string>("Title");
*
* See the documentation for more:
* https://docs.abp.io/en/abp/latest/Object-Extensions
*/
});
}
}
}

View File

@ -1,2 +1,3 @@
using System.Runtime.CompilerServices;
[assembly:InternalsVisibleToAttribute("KonSoft.TenantManagement.Application.Tests")]
[assembly: InternalsVisibleToAttribute("KonSoft.TenantManagement.Application.Tests")]

View File

@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
using KonSoft.TenantManagement.Localization;
using KonSoft.TenantManagement.Localization;
using Volo.Abp.Application.Services;
namespace KonSoft.TenantManagement;
@ -14,4 +11,4 @@ public abstract class TenantManagementAppService : ApplicationService
{
LocalizationResource = typeof(TenantManagementResource);
}
}
}

View File

@ -4,10 +4,4 @@ namespace KonSoft.TenantManagement;
public class TenantManagementApplicationAutoMapperProfile : Profile
{
public TenantManagementApplicationAutoMapperProfile()
{
/* You can configure your AutoMapper mapping configuration here.
* Alternatively, you can split your mapping configurations
* into multiple profile classes for a better organization. */
}
}
}

View File

@ -18,14 +18,11 @@ namespace KonSoft.TenantManagement;
typeof(AbpTenantManagementApplicationModule),
typeof(AbpFeatureManagementApplicationModule),
typeof(AbpSettingManagementApplicationModule)
)]
)]
public class TenantManagementApplicationModule : AbpModule
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
Configure<AbpAutoMapperOptions>(options =>
{
options.AddMaps<TenantManagementApplicationModule>();
});
Configure<AbpAutoMapperOptions>(options => { options.AddMaps<TenantManagementApplicationModule>(); });
}
}
}

View File

@ -5,5 +5,4 @@ namespace KonSoft.TenantManagement.Localization;
[LocalizationResourceName("TenantManagement")]
public class TenantManagementResource
{
}
}

View File

@ -7,4 +7,4 @@ public static class MultiTenancyConsts
* related modules and code parts, including this file.
*/
public const bool IsEnabled = true;
}
}

View File

@ -3,4 +3,4 @@
public static class TenantManagementDomainErrorCodes
{
/* You can add your business exception error codes here, as constants */
}
}

View File

@ -23,8 +23,8 @@ namespace KonSoft.TenantManagement;
typeof(AbpOpenIddictDomainSharedModule),
typeof(AbpPermissionManagementDomainSharedModule),
typeof(AbpSettingManagementDomainSharedModule),
typeof(AbpTenantManagementDomainSharedModule)
)]
typeof(AbpTenantManagementDomainSharedModule)
)]
public class TenantManagementDomainSharedModule : AbpModule
{
public override void PreConfigureServices(ServiceConfigurationContext context)
@ -55,4 +55,4 @@ public class TenantManagementDomainSharedModule : AbpModule
options.MapCodeNamespace("TenantManagement", typeof(TenantManagementResource));
});
}
}
}

View File

@ -4,19 +4,19 @@ namespace KonSoft.TenantManagement;
public static class TenantManagementGlobalFeatureConfigurator
{
private static readonly OneTimeRunner OneTimeRunner = new OneTimeRunner();
private static readonly OneTimeRunner OneTimeRunner = new();
public static void Configure()
{
OneTimeRunner.Run(() =>
{
/* You can configure (enable/disable) global features of the used modules here.
*
* YOU CAN SAFELY DELETE THIS CLASS AND REMOVE ITS USAGES IF YOU DON'T NEED TO IT!
*
* Please refer to the documentation to lear more about the Global Features System:
* https://docs.abp.io/en/abp/latest/Global-Features
*/
/* You can configure (enable/disable) global features of the used modules here.
*
* YOU CAN SAFELY DELETE THIS CLASS AND REMOVE ITS USAGES IF YOU DON'T NEED TO IT!
*
* Please refer to the documentation to lear more about the Global Features System:
* https://docs.abp.io/en/abp/latest/Global-Features
*/
});
}
}
}

View File

@ -1,13 +1,10 @@
using System.ComponentModel.DataAnnotations;
using Volo.Abp.Identity;
using Volo.Abp.ObjectExtending;
using Volo.Abp.Threading;
using Volo.Abp.Threading;
namespace KonSoft.TenantManagement;
public static class TenantManagementModuleExtensionConfigurator
{
private static readonly OneTimeRunner OneTimeRunner = new OneTimeRunner();
private static readonly OneTimeRunner OneTimeRunner = new();
public static void Configure()
{
@ -57,7 +54,7 @@ public static class TenantManagementModuleExtensionConfigurator
//validation rules
property.Attributes.Add(new RequiredAttribute());
property.Attributes.Add(new StringLengthAttribute(64) {MinimumLength = 4});
property.Configuration[IdentityModuleExtensionConsts.ConfigurationNames.AllowUserToEdit] = true;
//...other configurations for this property
@ -70,4 +67,4 @@ public static class TenantManagementModuleExtensionConfigurator
* https://docs.abp.io/en/abp/latest/Module-Entity-Extensions
*/
}
}
}

View File

@ -5,4 +5,4 @@ namespace KonSoft.TenantManagement.Data;
public interface ITenantManagementDbSchemaMigrator
{
Task MigrateAsync();
}
}

View File

@ -12,4 +12,4 @@ public class NullTenantManagementDbSchemaMigrator : ITenantManagementDbSchemaMig
{
return Task.CompletedTask;
}
}
}

View File

@ -17,12 +17,11 @@ namespace KonSoft.TenantManagement.Data;
public class TenantManagementDbMigrationService : ITransientDependency
{
public ILogger<TenantManagementDbMigrationService> Logger { get; set; }
private readonly ICurrentTenant _currentTenant;
private readonly IDataSeeder _dataSeeder;
private readonly IEnumerable<ITenantManagementDbSchemaMigrator> _dbSchemaMigrators;
private readonly ITenantRepository _tenantRepository;
private readonly ICurrentTenant _currentTenant;
public TenantManagementDbMigrationService(
IDataSeeder dataSeeder,
@ -38,6 +37,8 @@ public class TenantManagementDbMigrationService : ITransientDependency
Logger = NullLogger<TenantManagementDbMigrationService>.Instance;
}
public ILogger<TenantManagementDbMigrationService> Logger { get; set; }
public async Task MigrateAsync()
{
var initialMigrationAdded = AddInitialMigrationIfNotExist();
@ -52,7 +53,7 @@ public class TenantManagementDbMigrationService : ITransientDependency
await MigrateDatabaseSchemaAsync();
await SeedDataAsync();
Logger.LogInformation($"Successfully completed host database migrations.");
Logger.LogInformation("Successfully completed host database migrations.");
var tenants = await _tenantRepository.GetListAsync(includeDetails: true);
@ -101,8 +102,10 @@ public class TenantManagementDbMigrationService : ITransientDependency
Logger.LogInformation($"Executing {(tenant == null ? "host" : tenant.Name + " tenant")} database seed...");
await _dataSeeder.SeedAsync(new DataSeedContext(tenant?.Id)
.WithProperty(IdentityDataSeedContributor.AdminEmailPropertyName, IdentityDataSeedContributor.AdminEmailDefaultValue)
.WithProperty(IdentityDataSeedContributor.AdminPasswordPropertyName, IdentityDataSeedContributor.AdminPasswordDefaultValue)
.WithProperty(IdentityDataSeedContributor.AdminEmailPropertyName,
IdentityDataSeedContributor.AdminEmailDefaultValue)
.WithProperty(IdentityDataSeedContributor.AdminPasswordPropertyName,
IdentityDataSeedContributor.AdminPasswordDefaultValue)
);
}
@ -127,10 +130,8 @@ public class TenantManagementDbMigrationService : ITransientDependency
AddInitialMigration();
return true;
}
else
{
return false;
}
return false;
}
catch (Exception e)
{
@ -149,7 +150,8 @@ public class TenantManagementDbMigrationService : ITransientDependency
private bool MigrationsFolderExists()
{
var dbMigrationsProjectFolder = GetEntityFrameworkCoreProjectFolderPath();
return dbMigrationsProjectFolder != null && Directory.Exists(Path.Combine(dbMigrationsProjectFolder, "Migrations"));
return dbMigrationsProjectFolder != null &&
Directory.Exists(Path.Combine(dbMigrationsProjectFolder, "Migrations"));
}
private void AddInitialMigration()
@ -207,7 +209,8 @@ public class TenantManagementDbMigrationService : ITransientDependency
{
currentDirectory = Directory.GetParent(currentDirectory.FullName);
if (currentDirectory != null && Directory.GetFiles(currentDirectory.FullName).FirstOrDefault(f => f.EndsWith(".sln")) != null)
if (currentDirectory != null &&
Directory.GetFiles(currentDirectory.FullName).FirstOrDefault(f => f.EndsWith(".sln")) != null)
{
return currentDirectory.FullName;
}
@ -215,4 +218,4 @@ public class TenantManagementDbMigrationService : ITransientDependency
return null;
}
}
}

View File

@ -1,29 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Identity;
namespace KonSoft.TenantManagement.Entities
{
/// <summary>
/// 家政服务工人实体
/// </summary>
public class HouseholdWorker:IdentityUser
{
/// <summary>
/// 接单数
/// </summary>
public int OrderCount { get; set; }
/// <summary>
/// 职业
/// </summary>
public required string Profession { get; set; }
/// <summary>
/// 能力范围
/// </summary>
public required string ScopeOfCompetence { get; set; }
}
}

View File

@ -1,14 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using KonSoft.TenantManagement.Entities;
using Volo.Abp.Domain.Repositories;
namespace KonSoft.TenantManagement.IRepositories
{
public interface IHouseholdWorkerRepository: EfCoreRepository<AdminDbContext, Order>, IRepository<HouseholdWorker>
{
}
}

View File

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>

View File

@ -23,12 +23,12 @@ namespace KonSoft.TenantManagement.OpenIddict;
*/
public class OpenIddictDataSeedContributor : IDataSeedContributor, ITransientDependency
{
private readonly IAbpApplicationManager _applicationManager;
private readonly IConfiguration _configuration;
private readonly IOpenIddictApplicationRepository _openIddictApplicationRepository;
private readonly IAbpApplicationManager _applicationManager;
private readonly IOpenIddictScopeRepository _openIddictScopeRepository;
private readonly IOpenIddictScopeManager _scopeManager;
private readonly IPermissionDataSeeder _permissionDataSeeder;
private readonly IOpenIddictScopeManager _scopeManager;
private readonly IStringLocalizer<OpenIddictResponse> L;
public OpenIddictDataSeedContributor(
@ -38,7 +38,7 @@ public class OpenIddictDataSeedContributor : IDataSeedContributor, ITransientDep
IOpenIddictScopeRepository openIddictScopeRepository,
IOpenIddictScopeManager scopeManager,
IPermissionDataSeeder permissionDataSeeder,
IStringLocalizer<OpenIddictResponse> l )
IStringLocalizer<OpenIddictResponse> l)
{
_configuration = configuration;
_openIddictApplicationRepository = openIddictApplicationRepository;
@ -60,7 +60,8 @@ public class OpenIddictDataSeedContributor : IDataSeedContributor, ITransientDep
{
if (await _openIddictScopeRepository.FindByNameAsync("TenantManagement") == null)
{
await _scopeManager.CreateAsync(new OpenIddictScopeDescriptor {
await _scopeManager.CreateAsync(new OpenIddictScopeDescriptor
{
Name = "TenantManagement", DisplayName = "TenantManagement API", Resources = { "TenantManagement" }
});
}
@ -68,7 +69,8 @@ public class OpenIddictDataSeedContributor : IDataSeedContributor, ITransientDep
private async Task CreateApplicationsAsync()
{
var commonScopes = new List<string> {
var commonScopes = new List<string>
{
OpenIddictConstants.Permissions.Scopes.Address,
OpenIddictConstants.Permissions.Scopes.Email,
OpenIddictConstants.Permissions.Scopes.Phone,
@ -80,10 +82,6 @@ public class OpenIddictDataSeedContributor : IDataSeedContributor, ITransientDep
var configurationSection = _configuration.GetSection("OpenIddict:Applications");
// Swagger Client
var swaggerClientId = configurationSection["TenantManagement_Swagger:ClientId"];
if (!swaggerClientId.IsNullOrWhiteSpace())
@ -91,13 +89,13 @@ public class OpenIddictDataSeedContributor : IDataSeedContributor, ITransientDep
var swaggerRootUrl = configurationSection["TenantManagement_Swagger:RootUrl"]?.TrimEnd('/');
await CreateApplicationAsync(
name: swaggerClientId!,
type: OpenIddictConstants.ClientTypes.Public,
consentType: OpenIddictConstants.ConsentTypes.Implicit,
displayName: "Swagger Application",
secret: null,
grantTypes: [OpenIddictConstants.GrantTypes.AuthorizationCode],
scopes: commonScopes,
swaggerClientId!,
OpenIddictConstants.ClientTypes.Public,
OpenIddictConstants.ConsentTypes.Implicit,
"Swagger Application",
null,
[OpenIddictConstants.GrantTypes.AuthorizationCode],
commonScopes,
redirectUri: $"{swaggerRootUrl}/swagger/oauth2-redirect.html",
clientUri: swaggerRootUrl
);
@ -131,13 +129,14 @@ public class OpenIddictDataSeedContributor : IDataSeedContributor, ITransientDep
var client = await _openIddictApplicationRepository.FindByClientIdAsync(name);
var application = new AbpApplicationDescriptor {
var application = new AbpApplicationDescriptor
{
ClientId = name,
ClientType = type,
ClientSecret = secret,
ConsentType = consentType,
DisplayName = displayName,
ClientUri = clientUri,
ClientUri = clientUri
};
Check.NotNullOrEmpty(grantTypes, nameof(grantTypes));
@ -160,7 +159,8 @@ public class OpenIddictDataSeedContributor : IDataSeedContributor, ITransientDep
application.Permissions.Add(OpenIddictConstants.Permissions.Endpoints.Logout);
}
var buildInGrantTypes = new[] {
var buildInGrantTypes = new[]
{
OpenIddictConstants.GrantTypes.Implicit, OpenIddictConstants.GrantTypes.Password,
OpenIddictConstants.GrantTypes.AuthorizationCode, OpenIddictConstants.GrantTypes.ClientCredentials,
OpenIddictConstants.GrantTypes.DeviceCode, OpenIddictConstants.GrantTypes.RefreshToken
@ -233,7 +233,8 @@ public class OpenIddictDataSeedContributor : IDataSeedContributor, ITransientDep
}
}
var buildInScopes = new[] {
var buildInScopes = new[]
{
OpenIddictConstants.Permissions.Scopes.Address, OpenIddictConstants.Permissions.Scopes.Email,
OpenIddictConstants.Permissions.Scopes.Phone, OpenIddictConstants.Permissions.Scopes.Profile,
OpenIddictConstants.Permissions.Scopes.Roles
@ -289,8 +290,7 @@ public class OpenIddictDataSeedContributor : IDataSeedContributor, ITransientDep
await _permissionDataSeeder.SeedAsync(
ClientPermissionValueProvider.ProviderName,
name,
permissions,
null
permissions
);
}
@ -302,8 +302,10 @@ public class OpenIddictDataSeedContributor : IDataSeedContributor, ITransientDep
if (!HasSameRedirectUris(client, application))
{
client.RedirectUris = JsonSerializer.Serialize(application.RedirectUris.Select(q => q.ToString().TrimEnd('/')));
client.PostLogoutRedirectUris = JsonSerializer.Serialize(application.PostLogoutRedirectUris.Select(q => q.ToString().TrimEnd('/')));
client.RedirectUris =
JsonSerializer.Serialize(application.RedirectUris.Select(q => q.ToString().TrimEnd('/')));
client.PostLogoutRedirectUris =
JsonSerializer.Serialize(application.PostLogoutRedirectUris.Select(q => q.ToString().TrimEnd('/')));
await _applicationManager.UpdateAsync(client.ToModel());
}
@ -317,11 +319,13 @@ public class OpenIddictDataSeedContributor : IDataSeedContributor, ITransientDep
private bool HasSameRedirectUris(OpenIddictApplication existingClient, AbpApplicationDescriptor application)
{
return existingClient.RedirectUris == JsonSerializer.Serialize(application.RedirectUris.Select(q => q.ToString().TrimEnd('/')));
return existingClient.RedirectUris ==
JsonSerializer.Serialize(application.RedirectUris.Select(q => q.ToString().TrimEnd('/')));
}
private bool HasSameScopes(OpenIddictApplication existingClient, AbpApplicationDescriptor application)
{
return existingClient.Permissions == JsonSerializer.Serialize(application.Permissions.Select(q => q.ToString().TrimEnd('/')));
return existingClient.Permissions ==
JsonSerializer.Serialize(application.Permissions.Select(q => q.ToString().TrimEnd('/')));
}
}
}

View File

@ -1,3 +1,4 @@
using System.Runtime.CompilerServices;
[assembly:InternalsVisibleToAttribute("KonSoft.TenantManagement.Domain.Tests")]
[assembly:InternalsVisibleToAttribute("KonSoft.TenantManagement.TestBase")]
[assembly: InternalsVisibleToAttribute("KonSoft.TenantManagement.Domain.Tests")]
[assembly: InternalsVisibleToAttribute("KonSoft.TenantManagement.TestBase")]

View File

@ -9,4 +9,4 @@ public class TenantManagementSettingDefinitionProvider : SettingDefinitionProvid
//Define your own settings here. Example:
//context.Add(new SettingDefinition(TenantManagementSettings.MySetting1));
}
}
}

View File

@ -6,4 +6,4 @@ public static class TenantManagementSettings
//Add your own setting names here. Example:
//public const string MySetting1 = Prefix + ".MySetting1";
}
}

View File

@ -5,4 +5,4 @@ public static class TenantManagementConsts
public const string DbTablePrefix = "App";
public const string DbSchema = null;
}
}

View File

@ -1,6 +1,6 @@
using Microsoft.Extensions.DependencyInjection;
using KonSoft.TenantManagement.MultiTenancy;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using KonSoft.TenantManagement.MultiTenancy;
using Volo.Abp.AuditLogging;
using Volo.Abp.BackgroundJobs;
using Volo.Abp.Emailing;
@ -56,13 +56,10 @@ public class TenantManagementDomainModule : AbpModule
options.Languages.Add(new LanguageInfo("es", "es", "Español"));
});
Configure<AbpMultiTenancyOptions>(options =>
{
options.IsEnabled = MultiTenancyConsts.IsEnabled;
});
Configure<AbpMultiTenancyOptions>(options => { options.IsEnabled = MultiTenancyConsts.IsEnabled; });
#if DEBUG
context.Services.Replace(ServiceDescriptor.Singleton<IEmailSender, NullEmailSender>());
#endif
}
}
}

View File

@ -1,8 +1,8 @@
using System;
using System.Threading.Tasks;
using KonSoft.TenantManagement.Data;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using KonSoft.TenantManagement.Data;
using Volo.Abp.DependencyInjection;
namespace KonSoft.TenantManagement.EntityFrameworkCore;
@ -31,4 +31,4 @@ public class EntityFrameworkCoreTenantManagementDbSchemaMigrator
.Database
.MigrateAsync();
}
}
}

View File

@ -1,14 +0,0 @@
using KonSoft.TenantManagement.Entities;
using KonSoft.TenantManagement.IRepositories;
using Volo.Abp.Domain.Repositories.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore;
namespace KonSoft.TenantManagement.EntityFrameworkCore.Repositories
{
public class HouseholdWorkerRepository: EfCoreRepository<TenantManagementDbContext,HouseholdWorker>,IHouseholdWorkerRepository
{
public HouseholdWorkerRepository(IDbContextProvider<TenantManagementDbContext> dbContextProvider) : base(dbContextProvider)
{
}
}
}

View File

@ -1,5 +1,4 @@
using KonSoft.TenantManagement.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using Volo.Abp.AuditLogging.EntityFrameworkCore;
using Volo.Abp.BackgroundJobs.EntityFrameworkCore;
using Volo.Abp.Data;
@ -24,40 +23,9 @@ public class TenantManagementDbContext :
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 DbSet<HouseholdWorker> HouseholdWorkers { get; set; }
public TenantManagementDbContext(DbContextOptions<TenantManagementDbContext> options)
: base(options)
{
}
protected override void OnModelCreating(ModelBuilder builder)
@ -84,4 +52,35 @@ public class TenantManagementDbContext :
// //...
//});
}
}
/* 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
}

View File

@ -29,8 +29,8 @@ public class TenantManagementDbContextFactory : IDesignTimeDbContextFactory<Tena
{
var builder = new ConfigurationBuilder()
.SetBasePath(Path.Combine(Directory.GetCurrentDirectory(), "../KonSoft.TenantManagement.DbMigrator/"))
.AddJsonFile("appsettings.json", optional: false);
.AddJsonFile("appsettings.json", false);
return builder.Build();
}
}
}

View File

@ -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.TenantManagement.EntityFrameworkCore;
public static class TenantManagementEfCoreEntityExtensionMappings
{
private static readonly OneTimeRunner OneTimeRunner = new OneTimeRunner();
private static readonly OneTimeRunner OneTimeRunner = new();
public static void Configure()
{
@ -16,29 +13,29 @@ public static class TenantManagementEfCoreEntityExtensionMappings
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 TenantManagementModuleExtensionConfigurator 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 TenantManagementModuleExtensionConfigurator 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
*/
});
}
}
}

View File

@ -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.TenantManagement.EntityFrameworkCore;
typeof(AbpAuditLoggingEntityFrameworkCoreModule),
typeof(AbpTenantManagementEntityFrameworkCoreModule),
typeof(AbpFeatureManagementEntityFrameworkCoreModule)
)]
)]
public class TenantManagementEntityFrameworkCoreModule : AbpModule
{
public override void PreConfigureServices(ServiceConfigurationContext context)
@ -41,17 +40,16 @@ public class TenantManagementEntityFrameworkCoreModule : AbpModule
{
context.Services.AddAbpDbContext<TenantManagementDbContext>(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 TenantManagementMigrationsDbContextFactory for EF Core tooling. */
/* The main point to change your DBMS.
* See also TenantManagementMigrationsDbContextFactory for EF Core tooling. */
options.UseNpgsql();
});
}
}
}

View File

@ -29,4 +29,8 @@
<ProjectReference Include="..\KonSoft.TenantManagement.Domain\KonSoft.TenantManagement.Domain.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="EntityFrameworkCore\Repositories\" />
</ItemGroup>
</Project>

View File

@ -1,2 +1,3 @@
using System.Runtime.CompilerServices;
[assembly:InternalsVisibleToAttribute("KonSoft.TenantManagement.EntityFrameworkCore.Tests")]
[assembly: InternalsVisibleToAttribute("KonSoft.TenantManagement.EntityFrameworkCore.Tests")]

View File

@ -4,8 +4,8 @@ using Volo.Abp.FeatureManagement;
using Volo.Abp.Identity;
using Volo.Abp.Modularity;
using Volo.Abp.PermissionManagement;
using Volo.Abp.TenantManagement;
using Volo.Abp.SettingManagement;
using Volo.Abp.TenantManagement;
using Volo.Abp.VirtualFileSystem;
namespace KonSoft.TenantManagement;
@ -26,8 +26,7 @@ public class TenantManagementHttpApiClientModule : AbpModule
public override void ConfigureServices(ServiceConfigurationContext context)
{
context.Services.AddHttpClientProxies(
typeof(TenantManagementApplicationContractsModule).Assembly,
RemoteServiceName
typeof(TenantManagementApplicationContractsModule).Assembly
);
Configure<AbpVirtualFileSystemOptions>(options =>
@ -35,4 +34,4 @@ public class TenantManagementHttpApiClientModule : AbpModule
options.FileSets.AddEmbedded<TenantManagementHttpApiClientModule>();
});
}
}
}

View File

@ -11,4 +11,4 @@ public abstract class TenantManagementController : AbpControllerBase
{
LocalizationResource = typeof(TenantManagementResource);
}
}
}

View File

@ -7,4 +7,4 @@ public class TestModel
public string? Name { get; set; }
public DateTime BirthDate { get; set; }
}
}

View File

@ -1,5 +1,5 @@
using Localization.Resources.AbpUi;
using KonSoft.TenantManagement.Localization;
using KonSoft.TenantManagement.Localization;
using Localization.Resources.AbpUi;
using Volo.Abp.Account;
using Volo.Abp.FeatureManagement;
using Volo.Abp.Identity;
@ -19,7 +19,7 @@ namespace KonSoft.TenantManagement;
typeof(AbpTenantManagementHttpApiModule),
typeof(AbpFeatureManagementHttpApiModule),
typeof(AbpSettingManagementHttpApiModule)
)]
)]
public class TenantManagementHttpApiModule : AbpModule
{
public override void ConfigureServices(ServiceConfigurationContext context)
@ -38,4 +38,4 @@ public class TenantManagementHttpApiModule : AbpModule
);
});
}
}
}

View File

@ -1,5 +1,5 @@
using Shouldly;
using System.Threading.Tasks;
using System.Threading.Tasks;
using Shouldly;
using Volo.Abp.Identity;
using Volo.Abp.Modularity;
using Xunit;
@ -31,4 +31,4 @@ public abstract class SampleAppServiceTests<TStartupModule> : TenantManagementAp
result.TotalCount.ShouldBeGreaterThan(0);
result.Items.ShouldContain(u => u.UserName == "admin");
}
}
}

View File

@ -5,5 +5,4 @@ namespace KonSoft.TenantManagement;
public abstract class TenantManagementApplicationTestBase<TStartupModule> : TenantManagementTestBase<TStartupModule>
where TStartupModule : IAbpModule
{
}
}

View File

@ -8,5 +8,4 @@ namespace KonSoft.TenantManagement;
)]
public class TenantManagementApplicationTestModule : AbpModule
{
}
}

View File

@ -14,8 +14,8 @@ namespace KonSoft.TenantManagement.Samples;
public abstract class SampleDomainTests<TStartupModule> : TenantManagementDomainTestBase<TStartupModule>
where TStartupModule : IAbpModule
{
private readonly IIdentityUserRepository _identityUserRepository;
private readonly IdentityUserManager _identityUserManager;
private readonly IIdentityUserRepository _identityUserRepository;
protected SampleDomainTests()
{
@ -43,4 +43,4 @@ public abstract class SampleDomainTests<TStartupModule> : TenantManagementDomain
adminUser = await _identityUserRepository.FindByNormalizedUserNameAsync("ADMIN");
adminUser.Email.ShouldBe("newemail@abp.io");
}
}
}

View File

@ -6,5 +6,4 @@ namespace KonSoft.TenantManagement;
public abstract class TenantManagementDomainTestBase<TStartupModule> : TenantManagementTestBase<TStartupModule>
where TStartupModule : IAbpModule
{
}
}

View File

@ -8,5 +8,4 @@ namespace KonSoft.TenantManagement;
)]
public class TenantManagementDomainTestModule : AbpModule
{
}
}

View File

@ -6,5 +6,4 @@ namespace KonSoft.TenantManagement.EntityFrameworkCore.Applications;
[Collection(TenantManagementTestConsts.CollectionDefinitionName)]
public class EfCoreSampleAppServiceTests : SampleAppServiceTests<TenantManagementEntityFrameworkCoreTestModule>
{
}
}

View File

@ -6,5 +6,4 @@ namespace KonSoft.TenantManagement.EntityFrameworkCore.Domains;
[Collection(TenantManagementTestConsts.CollectionDefinitionName)]
public class EfCoreSampleDomainTests : SampleDomainTests<TenantManagementEntityFrameworkCoreTestModule>
{
}
}

View File

@ -1,8 +1,8 @@
using Microsoft.EntityFrameworkCore;
using Shouldly;
using System;
using System;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Shouldly;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.Identity;
using Xunit;
@ -32,13 +32,13 @@ public class SampleRepositoryTests : TenantManagementEntityFrameworkCoreTestBase
*/
await WithUnitOfWorkAsync(async () =>
{
//Act
var adminUser = await (await _appUserRepository.GetQueryableAsync())
//Act
var adminUser = await (await _appUserRepository.GetQueryableAsync())
.Where(u => u.UserName == "admin")
.FirstOrDefaultAsync();
//Assert
adminUser.ShouldNotBeNull();
//Assert
adminUser.ShouldNotBeNull();
});
}
}
}

View File

@ -3,7 +3,7 @@
namespace KonSoft.TenantManagement.EntityFrameworkCore;
[CollectionDefinition(TenantManagementTestConsts.CollectionDefinitionName)]
public class TenantManagementEntityFrameworkCoreCollection : ICollectionFixture<TenantManagementEntityFrameworkCoreFixture>
public class
TenantManagementEntityFrameworkCoreCollection : ICollectionFixture<TenantManagementEntityFrameworkCoreFixture>
{
}
}

View File

@ -1,9 +1,9 @@
using KonSoft.TenantManagement.EntityFrameworkCore;
using Xunit;
using Xunit;
namespace KonSoft.TenantManagement.EntityFrameworkCore;
public class TenantManagementEntityFrameworkCoreCollectionFixtureBase : ICollectionFixture<TenantManagementEntityFrameworkCoreFixture>
public class
TenantManagementEntityFrameworkCoreCollectionFixtureBase : ICollectionFixture<
TenantManagementEntityFrameworkCoreFixture>
{
}
}

View File

@ -6,6 +6,5 @@ public class TenantManagementEntityFrameworkCoreFixture : IDisposable
{
public void Dispose()
{
}
}
}

View File

@ -1,8 +1,7 @@
using Volo.Abp;
namespace KonSoft.TenantManagement.EntityFrameworkCore;
namespace KonSoft.TenantManagement.EntityFrameworkCore;
public abstract class TenantManagementEntityFrameworkCoreTestBase : TenantManagementTestBase<TenantManagementEntityFrameworkCoreTestModule>
public abstract class
TenantManagementEntityFrameworkCoreTestBase : TenantManagementTestBase<
TenantManagementEntityFrameworkCoreTestModule>
{
}
}

View File

@ -18,7 +18,7 @@ namespace KonSoft.TenantManagement.EntityFrameworkCore;
typeof(TenantManagementApplicationTestModule),
typeof(TenantManagementEntityFrameworkCoreModule),
typeof(AbpEntityFrameworkCoreSqliteModule)
)]
)]
public class TenantManagementEntityFrameworkCoreTestModule : AbpModule
{
private SqliteConnection? _sqliteConnection;
@ -51,10 +51,7 @@ public class TenantManagementEntityFrameworkCoreTestModule : AbpModule
services.Configure<AbpDbContextOptions>(options =>
{
options.Configure(context =>
{
context.DbContextOptions.UseSqlite(_sqliteConnection);
});
options.Configure(context => { context.DbContextOptions.UseSqlite(_sqliteConnection); });
});
}
@ -79,4 +76,4 @@ public class TenantManagementEntityFrameworkCoreTestModule : AbpModule
return connection;
}
}
}

View File

@ -22,4 +22,4 @@ public class ClientDemoService : ITransientDependency
Console.WriteLine($"Name : {output.Name}");
Console.WriteLine($"Surname : {output.Surname}");
}
}
}

View File

@ -1,8 +1,8 @@
using Microsoft.Extensions.Hosting;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Volo.Abp;
namespace KonSoft.TenantManagement.HttpApi.Client.ConsoleTestApp;
@ -18,11 +18,12 @@ public class ConsoleTestAppHostedService : IHostedService
public async Task StartAsync(CancellationToken cancellationToken)
{
using (var application = await AbpApplicationFactory.CreateAsync<TenantManagementConsoleApiClientModule>(options =>
{
options.Services.ReplaceConfiguration(_configuration);
options.UseAutofac();
}))
using (var application =
await AbpApplicationFactory.CreateAsync<TenantManagementConsoleApiClientModule>(options =>
{
options.Services.ReplaceConfiguration(_configuration);
options.UseAutofac();
}))
{
await application.InitializeAsync();
@ -37,4 +38,4 @@ public class ConsoleTestAppHostedService : IHostedService
{
return Task.CompletedTask;
}
}
}

View File

@ -1,22 +1,23 @@
using System.Threading.Tasks;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
namespace KonSoft.TenantManagement.HttpApi.Client.ConsoleTestApp;
class Program
internal class Program
{
static async Task Main(string[] args)
private static async Task Main(string[] args)
{
await CreateHostBuilder(args).RunConsoleAsync();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
public static IHostBuilder CreateHostBuilder(string[] args)
{
return Host.CreateDefaultBuilder(args)
.AddAppSettingsSecretsJson()
.ConfigureServices((hostContext, services) =>
{
services.AddHostedService<ConsoleTestAppHostedService>();
});
}
}
}

View File

@ -12,7 +12,7 @@ namespace KonSoft.TenantManagement.HttpApi.Client.ConsoleTestApp;
typeof(AbpAutofacModule),
typeof(TenantManagementHttpApiClientModule),
typeof(AbpHttpClientIdentityModelModule)
)]
)]
public class TenantManagementConsoleApiClientModule : AbpModule
{
public override void PreConfigureServices(ServiceConfigurationContext context)
@ -21,10 +21,10 @@ public class TenantManagementConsoleApiClientModule : AbpModule
{
options.ProxyClientBuildActions.Add((remoteServiceName, clientBuilder) =>
{
clientBuilder.AddTransientHttpErrorPolicy(
policyBuilder => policyBuilder.WaitAndRetryAsync(3, i => TimeSpan.FromSeconds(Math.Pow(2, i)))
clientBuilder.AddTransientHttpErrorPolicy(policyBuilder =>
policyBuilder.WaitAndRetryAsync(3, i => TimeSpan.FromSeconds(Math.Pow(2, i)))
);
});
});
}
}
}

View File

@ -17,9 +17,9 @@ public class FakeCurrentPrincipalAccessor : ThreadCurrentPrincipalAccessor
{
return new ClaimsPrincipal(new ClaimsIdentity(new List<Claim>
{
new Claim(AbpClaimTypes.UserId, "2e701e62-0953-4dd3-910b-dc6cc93ccb0d"),
new Claim(AbpClaimTypes.UserName, "admin"),
new Claim(AbpClaimTypes.Email, "admin@abp.io")
new(AbpClaimTypes.UserId, "2e701e62-0953-4dd3-910b-dc6cc93ccb0d"),
new(AbpClaimTypes.UserName, "admin"),
new(AbpClaimTypes.Email, "admin@abp.io")
}));
}
}
}

View File

@ -3,8 +3,8 @@ using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp;
using Volo.Abp.Modularity;
using Volo.Abp.Uow;
using Volo.Abp.Testing;
using Volo.Abp.Uow;
namespace KonSoft.TenantManagement;
@ -43,7 +43,8 @@ public abstract class TenantManagementTestBase<TStartupModule> : AbpIntegratedTe
return WithUnitOfWorkAsync(new AbpUnitOfWorkOptions(), func);
}
protected virtual async Task<TResult> WithUnitOfWorkAsync<TResult>(AbpUnitOfWorkOptions options, Func<Task<TResult>> func)
protected virtual async Task<TResult> WithUnitOfWorkAsync<TResult>(AbpUnitOfWorkOptions options,
Func<Task<TResult>> func)
{
using (var scope = ServiceProvider.CreateScope())
{
@ -57,4 +58,4 @@ public abstract class TenantManagementTestBase<TStartupModule> : AbpIntegratedTe
}
}
}
}
}

View File

@ -14,15 +14,12 @@ namespace KonSoft.TenantManagement;
typeof(AbpTestBaseModule),
typeof(AbpAuthorizationModule),
typeof(AbpBackgroundJobsAbstractionsModule)
)]
)]
public class TenantManagementTestBaseModule : AbpModule
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
Configure<AbpBackgroundJobOptions>(options =>
{
options.IsJobExecutionEnabled = false;
});
Configure<AbpBackgroundJobOptions>(options => { options.IsJobExecutionEnabled = false; });
context.Services.AddAlwaysAllowAuthorization();
}
@ -44,4 +41,4 @@ public class TenantManagementTestBaseModule : AbpModule
}
});
}
}
}

View File

@ -3,4 +3,4 @@
public static class TenantManagementTestConsts
{
public const string CollectionDefinitionName = "TenantManagement collection";
}
}

View File

@ -12,4 +12,4 @@ public class TenantManagementTestDataSeedContributor : IDataSeedContributor, ITr
return Task.CompletedTask;
}
}
}