Browse Source

Handle tenant creation event and create admin user and role for the new tenant.

pull/3032/head
Halil İbrahim Kalkan 6 years ago
parent
commit
2b0882bfde
  1. 1
      samples/MicroserviceDemo/microservices/IdentityService.Host/IdentityService.Host.csproj
  2. 5
      samples/MicroserviceDemo/microservices/IdentityService.Host/IdentityServiceHostModule.cs
  3. 38
      samples/MicroserviceDemo/microservices/IdentityService.Host/Tenants/TenantCreatedDistributedEventHandler.cs

1
samples/MicroserviceDemo/microservices/IdentityService.Host/IdentityService.Host.csproj

@ -29,6 +29,7 @@
<ProjectReference Include="..\..\..\..\modules\identity\src\Volo.Abp.Identity.HttpApi\Volo.Abp.Identity.HttpApi.csproj" />
<ProjectReference Include="..\..\..\..\modules\identity\src\Volo.Abp.Identity.EntityFrameworkCore\Volo.Abp.Identity.EntityFrameworkCore.csproj" />
<ProjectReference Include="..\..\..\..\modules\identity\src\Volo.Abp.Identity.Application\Volo.Abp.Identity.Application.csproj" />
<ProjectReference Include="..\..\..\..\modules\tenant-management\src\Volo.Abp.TenantManagement.EntityFrameworkCore\Volo.Abp.TenantManagement.EntityFrameworkCore.csproj" />
<ProjectReference Include="..\..\..\..\modules\audit-logging\src\Volo.Abp.AuditLogging.EntityFrameworkCore\Volo.Abp.AuditLogging.EntityFrameworkCore.csproj" />
<ProjectReference Include="..\..\..\..\modules\permission-management\src\Volo.Abp.PermissionManagement.EntityFrameworkCore\Volo.Abp.PermissionManagement.EntityFrameworkCore.csproj" />
<ProjectReference Include="..\..\..\..\modules\setting-management\src\Volo.Abp.SettingManagement.EntityFrameworkCore\Volo.Abp.SettingManagement.EntityFrameworkCore.csproj" />

5
samples/MicroserviceDemo/microservices/IdentityService.Host/IdentityServiceHostModule.cs

@ -7,7 +7,6 @@ using Microsoft.Extensions.DependencyInjection;
using StackExchange.Redis;
using Microsoft.OpenApi.Models;
using MsDemo.Shared;
using Swashbuckle.AspNetCore.Swagger;
using Volo.Abp;
using Volo.Abp.AspNetCore.MultiTenancy;
using Volo.Abp.Auditing;
@ -24,6 +23,7 @@ using Volo.Abp.MultiTenancy;
using Volo.Abp.PermissionManagement.EntityFrameworkCore;
using Volo.Abp.Security.Claims;
using Volo.Abp.SettingManagement.EntityFrameworkCore;
using Volo.Abp.TenantManagement.EntityFrameworkCore;
namespace IdentityService.Host
{
@ -37,7 +37,8 @@ namespace IdentityService.Host
typeof(AbpIdentityHttpApiModule),
typeof(AbpIdentityEntityFrameworkCoreModule),
typeof(AbpIdentityApplicationModule),
typeof(AbpAspNetCoreMultiTenancyModule)
typeof(AbpAspNetCoreMultiTenancyModule),
typeof(AbpTenantManagementEntityFrameworkCoreModule)
)]
public class IdentityServiceHostModule : AbpModule
{

38
samples/MicroserviceDemo/microservices/IdentityService.Host/Tenants/TenantCreatedDistributedEventHandler.cs

@ -0,0 +1,38 @@
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Volo.Abp.Data;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Domain.Entities.Events.Distributed;
using Volo.Abp.EventBus.Distributed;
using Volo.Abp.MultiTenancy;
using Volo.Abp.TenantManagement;
namespace IdentityService.Host.Tenants
{
public class TenantCreatedDistributedEventHandler : IDistributedEventHandler<EntityCreatedEto<TenantEto>>, ITransientDependency
{
public ILogger<TenantCreatedDistributedEventHandler> Logger { get; set; }
private readonly IDataSeeder _dataSeeder;
private readonly ICurrentTenant _currentTenant;
public TenantCreatedDistributedEventHandler(
IDataSeeder dataSeeder,
ICurrentTenant currentTenant)
{
_dataSeeder = dataSeeder;
_currentTenant = currentTenant;
Logger = NullLogger<TenantCreatedDistributedEventHandler>.Instance;
}
public async Task HandleEventAsync(EntityCreatedEto<TenantEto> eventData)
{
Logger.LogInformation($"Handled distributed event for a new tenant creation. TenantId: {eventData.Entity.Id}");
using (_currentTenant.Change(eventData.Entity.Id, eventData.Entity.Name))
{
await _dataSeeder.SeedAsync(tenantId: eventData.Entity.Id);
}
}
}
}
Loading…
Cancel
Save