Change tenant in all derived class of IDataSeedContributor

pull/5624/head
liangshiwei 4 years ago
parent fee0569b3b
commit 3831d13e4d

@ -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
));
}
}
}
}

@ -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()

@ -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()

Loading…
Cancel
Save