Open Closed

How to get extended property from tenant ? #7913


User avatar
0
nabass created
  • ABP Framework version: v8.0.2
  • UI Type: MVC
  • Database System: EF Core (SQL Server)
  • Tiered (for MVC) or Auth Server Separated (for Angular): MVC /Auth Server Separated (NO)
  • Exception message and full stack trace:
  • Steps to reproduce the issue: I create extended property on tenant like this code
private static void ConfigureExtraProperties()
{
    OneTimeRunner.Run(() =>
    {  ObjectExtensionManager.Instance.Modules()
     .ConfigureSaas(tenant =>
     {
         tenant.ConfigureTenant(tnt =>
         {
            
             tnt.AddOrUpdateProperty<EnvironmentMode>(
                 "EnvironmentMode"
                   , property =>
                   {
                       property.DisplayName = LocalizableString.Create<CoreSettingResource>("EnvironmentMode");
                       property.Attributes.Add(new RequiredAttribute());
                   });
                          });



});

//========================== and already appear in Create and edit tenant page and list of tenant page and saved on Tenant table but i have issue how i get the values from this extended property i tried to use IDistributedEventHandler and create new class in application project in src folder like that

 public class CustomTenantDistributedHandler:
 IDistributedEventHandler<EntityCreatedEto<TenantEto>>,
 ITransientDependency
 {
     [UnitOfWork]
     public async Task HandleEventAsync(EntityCreatedEto<TenantEto> eventData)
     {
         var tenantId = eventData.Entity.Id;
         var tenantName = eventData.Entity.Name;
         //...your custom logic
     }

     //...
 }

//================ but this event not fire can you advice ?


4 Answer(s)
  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    you can try

    public class CustomTenantDistributedHandler :
        IDistributedEventHandler<TenantCreatedEto>
    {
    
        public async Task HandleEventAsync(TenantCreatedEto eventData)
        {
            ....
        }
    
    }
    
  • User Avatar
    0
    nabass created

    Thank you, it's working and event can fire now but i make this event to access extra properties "TaxRegisterationNo" in tenant but it is not found in TenantCreateEto

    public class CustomTenantDistributedHandler : ILocalEventHandler<TenantCreatedEto>, ITransientDependency {

     public async Task HandleEventAsync(TenantCreatedEto eventData)
     {
         var tenantId = eventData.Id;
         var tenantName = eventData.Name;
         var TaxRegisterationNo = eventData.Properties["TaxRegisterationNo"].ToString();
         //...your custom logic
     }
    
     //...
    

    }

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    you can get tenant entity here.

    var tenant = await tenantRepository.FindAsync(eventData.Id);
    
  • User Avatar
    0
    nabass created

    Thank you for your response, and i want mention that i can't reach this tenantRepository because i want to use it in seeder in domain application and when i add reference for tenant management, show error that is not compatible with netstandard 2.0 ,so i use public async Task HandleEventAsync(EntityCreatedEventData<Tenant> eventData) {} as you mention before but i change argument to be EntityCreatedEventData<Tenant> and it works fine Thank you again

Made with ❤️ on ABP v9.1.0-preview. Updated on October 11, 2024, 07:13