diff --git a/src/Contrib/StackSdks/Masa.Contrib.StackSdks.Isolation/IsolationConfigurationApi.cs b/src/Contrib/StackSdks/Masa.Contrib.StackSdks.Isolation/IsolationConfigurationApi.cs index 6c56e3b45..9773e2b7e 100644 --- a/src/Contrib/StackSdks/Masa.Contrib.StackSdks.Isolation/IsolationConfigurationApi.cs +++ b/src/Contrib/StackSdks/Masa.Contrib.StackSdks.Isolation/IsolationConfigurationApi.cs @@ -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(); } public IConfiguration Get(string appId) { - var multiEnvironmentContext = _httpContextAccessor.HttpContext!.RequestServices.GetRequiredService(); - var environment = multiEnvironmentContext.CurrentEnvironment; + var multiEnvironmentContext = _httpContextAccessor.HttpContext?.RequestServices.GetService(); + var environment = multiEnvironmentContext?.CurrentEnvironment; if (environment.IsNullOrEmpty()) { - var multiEnvironmentUserContext = _httpContextAccessor.HttpContext!.RequestServices.GetRequiredService(); - environment = multiEnvironmentUserContext.Environment; + var multiEnvironmentUserContext = _httpContextAccessor.HttpContext?.RequestServices.GetService(); + environment = multiEnvironmentUserContext?.Environment; + } + + if (environment.IsNullOrEmpty()) + { + environment = _stackConfig.Environment; } if (environment.IsNullOrEmpty()) {