Hi,
I have the following code:
[UnitOfWork]
public async Task GetFinancialConnector(AdministrationIdentifier administration)
{
var results1 = _administrationRepository.GetAllList(); // Returns all 8 administrations --> correct
UnitOfWorkManager.Current.SetTenantId(administration.TenantId);
var results2 = _administrationRepository.GetAllList(); // Returns 0 administrations --> incorrect!
UnitOfWorkManager.Current.SetTenantId(administration.TenantId);
var results3 = _administrationRepository.GetAllList(); // Returns all 8 administrations --> correct
}
Administration implements IMustHaveTenant. This method is called with a non null value for administration.TenantId, e.g. 1.
After calling SetTenantId the first time _administrationRepository.GetAllList() doesn't return any results. At this moment FilterParameter MustHaveTenant has no parameters, which is strange because SetTenantId was called before with a tenant id. After calling SetTenantId the second time _administrationRepository.GetAllList() returns the correct results. At this moment the parameter of MustHaveTenant is correctly set.
Can someone clarify why calling SetTenantId once doesn't give the desired result?
Note: this code is running in a console app. AbpSession.TenantId is null. If I register a custom IAbpSession and set TenantId to a non null value, calling SetTenantId once works perfectly.
Thanks.
Kind regards,
Nik
6 Answer(s)
-
0
Hi,
Is your GetFinancialConnector method called over an iterface? How do you inject it while using. Also, is it application service? Did you try to make this method virtual?
-
0
Is your GetFinancialConnector method called over an iterface?
Yes it is.
How do you inject it while using.
In the console app I use AbpBootstrapper. To resolve IFinancialConnectorService I use:
IFinancialConnectorService financialConnectorService = IocManager.Instance.Resolve<IFinancialConnectorService>();
Also, is it application service?
No, the base class of FinancialConnectorService is MyAppServiceBase. FinancialConnectorService furthermore implements ITransientDependency.
Did you try to make this method virtual?
Yes, this doesn't change anything.
-
0
Thank you for your answers. Let us deeply check and test it.
-
0
Can you try to enable filter first:
unitOfWorkManager.Current.EnableFilter(AbpDataFilters.MustHaveTenant);
Write this before first SetTenantId()
-
0
This works correctly, thank you. Should I always call UnitOfWorkManager.Current.EnableFilter(AbpDataFilters.MustHaveTenant) before calling UnitOfWorkManager.Current.SetTenantId or is the observed behaviour considered a bug?
-
0
Hi,
Normally, yes, you should enable a filter before setting it's value.
But I made it automatically: When you set it to a non-null value, MustHaveTenant filter will be automatically enabled. This will be released with ABP v0.9.2.
Thanks.