Open Closed

CurrentTenant & Extra Property #2359


User avatar
0
serdar.genc@talentra.net created

Hi,

I added TenantType as an extra property to Tenant. how can i add it to CurrentTenant. I want to call it like this: CurrentTenant.TenantType etc.

  • ABP Framework version: v5.0.1
  • UI type: MVC
  • DB provider: EF Core
  • Tiered (MVC) or Identity Server Separated (Angular): no

3 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    See https://docs.abp.io/en/abp/latest/Authorization#claims-principal-factory

    
    public static class CurrentUserExtensions
    {
        public static string GetSocialSecurityNumber(this ICurrentUser currentUser)
        {
            return currentUser.FindClaimValue("SocialSecurityNumber");
        }
    }
    
  • User Avatar
    0
    EngincanV created
    Support Team .NET Developer

    Hi @Serdar, you need to override the CurrentTenant class, get the tenant by current tenant id and access the Extra Property dictionary of the tenant.

    [Dependency(ReplaceServices = true)]
    [ExposeServices(typeof(ICurrentTenant), typeof(CurrentTenant), typeof(MyCurrentTenant))]
    public class MyCurrentTenant : CurrentTenant
    {   
       private readonly ITenantRepository _tenantRepository;
       
       public MyCurrentTenant(ICurrentTenantAccessor currentTenantAccessor, ITenantRepository tenantRepository):base(currentTenantAccessor)
        {
            _tenantRepository = tenantRepository;
        } 
        
       public async Task<Dictionary<string, object>> GetExtraProperties() 
       {
           if(!base.Id.HasValue) 
           {    
               return new Dictionary<string, object>();
           }
           
           var tenant = await _tenantRepository.GetAsync(base.Id);
           //implement your logic
           //tenant.ExtraProperty ...
       }
    }
    
    
  • User Avatar
    0
    serdar.genc@talentra.net created

    Hi @Serdar, you need to override the CurrentTenant class, get the tenant by current tenant id and access the Extra Property dictionary of the tenant.

    [Dependency(ReplaceServices = true)] 
    [ExposeServices(typeof(ICurrentTenant), typeof(CurrentTenant), typeof(MyCurrentTenant))] 
    public class MyCurrentTenant : CurrentTenant 
    {    
       private readonly ITenantRepository _tenantRepository; 
        
       public MyCurrentTenant(ICurrentTenantAccessor currentTenantAccessor, ITenantRepository tenantRepository):base(currentTenantAccessor) 
        { 
            _tenantRepository = tenantRepository; 
        }  
         
       public async Task<Dictionary<string, object>> GetExtraProperties()  
       { 
           if(!base.Id.HasValue)  
           {     
               return new Dictionary<string, object>(); 
           } 
            
           var tenant = await _tenantRepository.GetAsync(base.Id); 
           //implement your logic 
           //tenant.ExtraProperty ... 
       } 
    } 
     
    

    tesekkurler @EnginCanV.

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