diff --git a/framework/src/Volo.Abp.AspNetCore/Microsoft/Extensions/DependencyInjection/AbpAspNetCoreServiceCollectionExtensions.cs b/framework/src/Volo.Abp.AspNetCore/Microsoft/Extensions/DependencyInjection/AbpAspNetCoreServiceCollectionExtensions.cs index d672952b09..41f0a16167 100644 --- a/framework/src/Volo.Abp.AspNetCore/Microsoft/Extensions/DependencyInjection/AbpAspNetCoreServiceCollectionExtensions.cs +++ b/framework/src/Volo.Abp.AspNetCore/Microsoft/Extensions/DependencyInjection/AbpAspNetCoreServiceCollectionExtensions.cs @@ -8,7 +8,9 @@ namespace Microsoft.Extensions.DependencyInjection { public static IWebHostEnvironment GetHostingEnvironment(this IServiceCollection services) { - if (!services.Any(d => d.ServiceType == typeof(IWebHostEnvironment))) + var hostingEnvironment = services.GetSingletonInstanceOrNull(); + + if (hostingEnvironment == null) { return new EmptyHostingEnvironment() { @@ -16,7 +18,7 @@ namespace Microsoft.Extensions.DependencyInjection }; } - return services.GetSingletonInstance(); + return hostingEnvironment; } } }