Skip to content

Commit

Permalink
Fix tenantId is null bug when UserInfo has not been accessed
Browse files Browse the repository at this point in the history
  • Loading branch information
BlueBasher committed Oct 5, 2024
1 parent 4fedc01 commit 658ec82
Showing 1 changed file with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@ namespace PlatformPlatform.SharedKernel.ExecutionContext;

public class HttpExecutionContext(IHttpContextAccessor httpContextAccessor) : IExecutionContext
{
private bool _isTenantIdCalculated;
private TenantId? _tenantId;
private UserInfo? _userInfo;

public TenantId? TenantId
{
get
{
// The first time this property is accessed, _userInfo might be null, but when TenantId.TryParse() is called,
// it will be set. So even if _tenantId is null, we know if this property has been accessed before.
if (_userInfo is not null)
if (_isTenantIdCalculated)
{
return _tenantId;
}

TenantId.TryParse(UserInfo.TenantId, out _tenantId);
_isTenantIdCalculated = true;
return _tenantId;
}
}
Expand Down

0 comments on commit 658ec82

Please sign in to comment.