Base solution for your next web application
Open Closed

Tenant - Auto populate Settings #6294


User avatar
0
Hercules created

Hi,

I have created some settings for each tenant, that I wish to be autopopulated once a tenant is created.

How can I accomplish such functionality?


12 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @Hercules

    Are you willing to change the default values of settings for each Tenant ? If not, you can modify the default setting values.

    If you want to insert different settings for each tenant, you need to do it in TenantManager's CreateWithAdminUserAsync method.

  • User Avatar
    0
    Hercules created

    Thank you ismcagdas

    Maybe I wasn't clear enough on my question.

    I have created some settings i.e. Countries and I want each tenant to have full control over the Countries of their application.

    I also want as soon as the Tenant is created, that I autopopulate a list of countries to start with, before the end user can perform CRUD operations on the Countries settings page.

    How can I set a "signal" that as soon as tenant is created, it should autopopulate ot the the Countries Table linked with the Tenant's ID?

  • User Avatar
    0
    aaron created
    Support Team

    https://aspnetboilerplate.com/Pages/Documents/EventBus-Domain-Events

  • User Avatar
    0
    Hercules created

    Hi again,

    Since Tenant is already CRUDed by abp is there any event already implemented for this purpose when a tenant is created?

  • User Avatar
    0
    aaron created
    Support Team

    Yes, read the section on Entity Changes.

  • User Avatar
    0
    ismcagdas created
    Support Team

    @Hercules

    There is no such an event for Tenant creation, you need to trigger and handle it by yourself according to https://aspnetboilerplate.com/Pages/Documents/EventBus-Domain-Events as @aaron shared. It is very easy to implement.

  • User Avatar
    0
    Hercules created

    Thank you for the answer.

    Can we create the Event in the TenantAppService uder the followign method:

    public async Task CreateTenant(CreateTenantInput input) {}

    Or is there any better place to do it?

  • User Avatar
    0
    ryancyq created
    Support Team

    you can create a separate class to handle this.

    Similar to UserFriendCacheSyncronizer in ANZ project

  • User Avatar
    0
    Hercules created

    I have created the below Event Manager, which is calling a method that contains the seed data that I wish to autopopulate the tenant upon creation.

        public TenantInitializerEventManager(ITenantInitializerService tenantInitializerService)
        {
            this.tenantInitializerService = tenantInitializerService;
        }
    
        public void HandleEvent(EntityCreatedEventData<Tenant> eventData)
        {
            this.tenantInitializerService.CreateNewTenantSeedData(eventData.Entity);
        }
    

    This Event is not fired when a tenant is created, where do I declare to execute the Event?

  • User Avatar
    0
    aaron created
    Support Team

    Show the class definition.

  • User Avatar
    0
    Hercules created

    public class TenantInitializerEventManager : IEventHandler<EntityCreatedEventData<Tenant>> { private readonly ITenantInitializerService tenantInitializerService;

        public TenantInitializerEventManager(ITenantInitializerService tenantInitializerService)
        {
            this.tenantInitializerService = tenantInitializerService;
        }
    
        public void HandleEvent(EntityCreatedEventData&lt;Tenant&gt; eventData)
        {
            this.tenantInitializerService.CreateNewTenantSeedData(eventData.Entity);
        }
    }
    
  • User Avatar
    0
    aaron created
    Support Team

    Implement ITransientDependency.