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
Markdown supported.
Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)

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");
        }
    }
    
    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • 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 ...
       }
    }
    
    
    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • 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.

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v10.8.0-preview. Updated on September 28, 2026, 11:44
1
ABP Assistant
🔐 You need to be logged in to use the chatbot. Please log in first.