diff --git a/modules/cms-kit/test/Volo.CmsKit.TestBase/CmsKitDataSeedContributor.cs b/modules/cms-kit/test/Volo.CmsKit.TestBase/CmsKitDataSeedContributor.cs index f91e79fb84..e2231570b9 100644 --- a/modules/cms-kit/test/Volo.CmsKit.TestBase/CmsKitDataSeedContributor.cs +++ b/modules/cms-kit/test/Volo.CmsKit.TestBase/CmsKitDataSeedContributor.cs @@ -2,6 +2,7 @@ using Volo.Abp.Data; using Volo.Abp.DependencyInjection; using Volo.Abp.Guids; +using Volo.Abp.MultiTenancy; using Volo.Abp.Users; using Volo.CmsKit.Comments; using Volo.CmsKit.Ratings; @@ -18,6 +19,7 @@ namespace Volo.CmsKit private readonly ICommentRepository _commentRepository; private readonly ReactionManager _reactionManager; private readonly IRatingRepository _ratingRepository; + private readonly ICurrentTenant _currentTenant; public CmsKitDataSeedContributor( IGuidGenerator guidGenerator, @@ -25,7 +27,8 @@ namespace Volo.CmsKit CmsKitTestData cmsKitTestData, ICommentRepository commentRepository, ReactionManager reactionManager, - IRatingRepository ratingRepository) + IRatingRepository ratingRepository, + ICurrentTenant currentTenant) { _guidGenerator = guidGenerator; _cmsUserRepository = cmsUserRepository; @@ -33,17 +36,21 @@ namespace Volo.CmsKit _commentRepository = commentRepository; _reactionManager = reactionManager; _ratingRepository = ratingRepository; + _currentTenant = currentTenant; } public async Task SeedAsync(DataSeedContext context) { - await SeedUsersAsync(); + using (_currentTenant.Change(context.TenantId)) + { + await SeedUsersAsync(); - await SeedCommentsAsync(); + await SeedCommentsAsync(); - await SeedReactionsAsync(); + await SeedReactionsAsync(); - await SeedRatingsAsync(); + await SeedRatingsAsync(); + } } private async Task SeedUsersAsync() @@ -148,21 +155,21 @@ namespace Volo.CmsKit 4, _cmsKitTestData.User1Id )); - + await _ratingRepository.InsertAsync(new Rating(_guidGenerator.Create(), _cmsKitTestData.EntityType1, _cmsKitTestData.EntityId1, 5, _cmsKitTestData.User1Id )); - + await _ratingRepository.InsertAsync(new Rating(_guidGenerator.Create(), _cmsKitTestData.EntityType2, _cmsKitTestData.EntityId2, 5, _cmsKitTestData.User2Id )); - + await _ratingRepository.InsertAsync(new Rating(_guidGenerator.Create(), _cmsKitTestData.EntityType2, _cmsKitTestData.EntityId2, @@ -171,4 +178,4 @@ namespace Volo.CmsKit )); } } -} \ No newline at end of file +} diff --git a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Domain/IdentityServer/IdentityServerDataSeedContributor.cs b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Domain/IdentityServer/IdentityServerDataSeedContributor.cs index dcd105a4e9..fb87b48303 100644 --- a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Domain/IdentityServer/IdentityServerDataSeedContributor.cs +++ b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Domain/IdentityServer/IdentityServerDataSeedContributor.cs @@ -10,6 +10,7 @@ using Volo.Abp.Guids; using Volo.Abp.IdentityServer.ApiResources; using Volo.Abp.IdentityServer.Clients; using Volo.Abp.IdentityServer.IdentityResources; +using Volo.Abp.MultiTenancy; using Volo.Abp.PermissionManagement; using Volo.Abp.Uow; using ApiResource = Volo.Abp.IdentityServer.ApiResources.ApiResource; @@ -25,6 +26,7 @@ namespace MyCompanyName.MyProjectName.IdentityServer private readonly IGuidGenerator _guidGenerator; private readonly IPermissionDataSeeder _permissionDataSeeder; private readonly IConfiguration _configuration; + private readonly ICurrentTenant _currentTenant; public IdentityServerDataSeedContributor( IClientRepository clientRepository, @@ -32,7 +34,8 @@ namespace MyCompanyName.MyProjectName.IdentityServer IIdentityResourceDataSeeder identityResourceDataSeeder, IGuidGenerator guidGenerator, IPermissionDataSeeder permissionDataSeeder, - IConfiguration configuration) + IConfiguration configuration, + ICurrentTenant currentTenant) { _clientRepository = clientRepository; _apiResourceRepository = apiResourceRepository; @@ -40,14 +43,18 @@ namespace MyCompanyName.MyProjectName.IdentityServer _guidGenerator = guidGenerator; _permissionDataSeeder = permissionDataSeeder; _configuration = configuration; + _currentTenant = currentTenant; } [UnitOfWork] public virtual async Task SeedAsync(DataSeedContext context) { - await _identityResourceDataSeeder.CreateStandardResourcesAsync(); - await CreateApiResourcesAsync(); - await CreateClientsAsync(); + using (_currentTenant.Change(context.TenantId)) + { + await _identityResourceDataSeeder.CreateStandardResourcesAsync(); + await CreateApiResourcesAsync(); + await CreateClientsAsync(); + } } private async Task CreateApiResourcesAsync() diff --git a/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.IdentityServer/IdentityServer/IdentityServerDataSeedContributor.cs b/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.IdentityServer/IdentityServer/IdentityServerDataSeedContributor.cs index 593169ae48..bff1f28f30 100644 --- a/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.IdentityServer/IdentityServer/IdentityServerDataSeedContributor.cs +++ b/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.IdentityServer/IdentityServer/IdentityServerDataSeedContributor.cs @@ -9,6 +9,7 @@ using Volo.Abp.Guids; using Volo.Abp.IdentityServer.ApiResources; using Volo.Abp.IdentityServer.Clients; using Volo.Abp.IdentityServer.IdentityResources; +using Volo.Abp.MultiTenancy; using Volo.Abp.PermissionManagement; using Volo.Abp.Uow; @@ -22,6 +23,7 @@ namespace MyCompanyName.MyProjectName.IdentityServer private readonly IGuidGenerator _guidGenerator; private readonly IPermissionDataSeeder _permissionDataSeeder; private readonly IConfiguration _configuration; + private readonly ICurrentTenant _currentTenant; public IdentityServerDataSeedContributor( IClientRepository clientRepository, @@ -29,7 +31,8 @@ namespace MyCompanyName.MyProjectName.IdentityServer IIdentityResourceDataSeeder identityResourceDataSeeder, IGuidGenerator guidGenerator, IPermissionDataSeeder permissionDataSeeder, - IConfiguration configuration) + IConfiguration configuration, + ICurrentTenant currentTenant) { _clientRepository = clientRepository; _apiResourceRepository = apiResourceRepository; @@ -37,14 +40,18 @@ namespace MyCompanyName.MyProjectName.IdentityServer _guidGenerator = guidGenerator; _permissionDataSeeder = permissionDataSeeder; _configuration = configuration; + _currentTenant = currentTenant; } [UnitOfWork] public virtual async Task SeedAsync(DataSeedContext context) { - await _identityResourceDataSeeder.CreateStandardResourcesAsync(); - await CreateApiResourcesAsync(); - await CreateClientsAsync(); + using (_currentTenant.Change(context.TenantId)) + { + await _identityResourceDataSeeder.CreateStandardResourcesAsync(); + await CreateApiResourcesAsync(); + await CreateClientsAsync(); + } } private async Task CreateApiResourcesAsync()