Skip to content

Commit

Permalink
fix:httpcontext null issue (#662)
Browse files Browse the repository at this point in the history
* fix:httpcontext null issue

* fix:di
  • Loading branch information
MayueCif authored Jul 31, 2023
1 parent 00d8faa commit 5e3d5c6
Showing 1 changed file with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,31 @@ internal class IsolationConfigurationApi : IConfigurationApi
{
readonly IConfiguration _configuration;
readonly IHttpContextAccessor _httpContextAccessor;
readonly IMasaStackConfig _stackConfig;

public IsolationConfigurationApi(
IConfiguration configuration,
IHttpContextAccessor httpContextAccessor)
IHttpContextAccessor httpContextAccessor,
IServiceProvider serviceProvider)
{
_configuration = configuration;
_httpContextAccessor = httpContextAccessor;
_stackConfig = serviceProvider.CreateScope().ServiceProvider.GetRequiredService<IMasaStackConfig>();
}

public IConfiguration Get(string appId)
{
var multiEnvironmentContext = _httpContextAccessor.HttpContext!.RequestServices.GetRequiredService<IMultiEnvironmentContext>();
var environment = multiEnvironmentContext.CurrentEnvironment;
var multiEnvironmentContext = _httpContextAccessor.HttpContext?.RequestServices.GetService<IMultiEnvironmentContext>();
var environment = multiEnvironmentContext?.CurrentEnvironment;
if (environment.IsNullOrEmpty())
{
var multiEnvironmentUserContext = _httpContextAccessor.HttpContext!.RequestServices.GetRequiredService<IMultiEnvironmentUserContext>();
environment = multiEnvironmentUserContext.Environment;
var multiEnvironmentUserContext = _httpContextAccessor.HttpContext?.RequestServices.GetService<IMultiEnvironmentUserContext>();
environment = multiEnvironmentUserContext?.Environment;
}

if (environment.IsNullOrEmpty())
{
environment = _stackConfig.Environment;
}
if (environment.IsNullOrEmpty())
{
Expand Down

0 comments on commit 5e3d5c6

Please sign in to comment.