Base solution for your next web application
Ends in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Abp Session Or Get Current Tenancy Name in Contructor Without Injecting in parameter #6307


User avatar
0
OriAssurant created

I am trying to get Current Tenant Name Or AbpSession in Constructor without parameter injection.

Working Code: public class CommonAllService : AppServiceBase { public IIMEIInformation _iMEIInformation { protected get; set; } private readonly IConfigurationRoot _configAccessor; private string _tenancyName; private readonly IAbpSession _session; public CommonAllService(IConfigurationRoot configAccessor,IAbpSession session) { _configAccessor = configAccessor; _session = session; _iMEIInformation = TenantDepedencyResolver.Resolve(_tenancyName); } public async Task GetDeviceInfo(GetIMEIRequest getImeiRequest) { return await _iMEIInformation.GetIMEIInformation(getImeiRequest); } }

we are Looking to get TenancyName or AbpSession without injecting in constructor? public class CommonAllService : AppServiceBase { public CommonAllService(IConfigurationRoot configAccessor) { _configAccessor = configAccessor; //Coming as Null var session = AbpSession.TenantId(); //Throwing abpexception GetCurrentTenant() its null var abc = GetCurrentTenant().TenancyName; _iMEIInformation = TenantDepedencyResolver.Resolve(_tenancyName); } }


1 Answer(s)
  • User Avatar
    1
    maliming created
    Support Team

    https://github.com/aspnetboilerplate/aspnetboilerplate/blob/e0ded5d8702f389aa1f5947d3446f16aec845287/src/Abp/Application/Services/ApplicationService.cs#L51

    For design reasons, you'd better use dependency injection.