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 cc88cac891..bda87a4e32 100644 --- a/framework/src/Volo.Abp.AspNetCore/Microsoft/Extensions/DependencyInjection/AbpAspNetCoreServiceCollectionExtensions.cs +++ b/framework/src/Volo.Abp.AspNetCore/Microsoft/Extensions/DependencyInjection/AbpAspNetCoreServiceCollectionExtensions.cs @@ -1,4 +1,6 @@ -using Microsoft.AspNetCore.Hosting; +using System.Linq; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Hosting; namespace Microsoft.Extensions.DependencyInjection; @@ -6,6 +8,16 @@ public static class AbpAspNetCoreServiceCollectionExtensions { public static IWebHostEnvironment GetHostingEnvironment(this IServiceCollection services) { - return services.GetSingletonInstance(); + var hostingEnvironment = services.GetSingletonInstanceOrNull(); + + if (hostingEnvironment == null) + { + return new EmptyHostingEnvironment() + { + EnvironmentName = Environments.Development + }; + } + + return hostingEnvironment; } } diff --git a/framework/src/Volo.Abp.AspNetCore/Microsoft/Extensions/DependencyInjection/EmptyHostingEnvironment.cs b/framework/src/Volo.Abp.AspNetCore/Microsoft/Extensions/DependencyInjection/EmptyHostingEnvironment.cs new file mode 100644 index 0000000000..371162f0da --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore/Microsoft/Extensions/DependencyInjection/EmptyHostingEnvironment.cs @@ -0,0 +1,19 @@ +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.FileProviders; + +namespace Microsoft.Extensions.DependencyInjection; + +internal class EmptyHostingEnvironment : IWebHostEnvironment +{ + public string EnvironmentName { get; set; } + + public string ApplicationName { get; set; } + + public string WebRootPath { get; set; } + + public IFileProvider WebRootFileProvider { get; set; } + + public string ContentRootPath { get; set; } + + public IFileProvider ContentRootFileProvider { get; set; } +} \ No newline at end of file diff --git a/test/DistEvents/DistDemoApp.Shared/DistDemoApp.Shared.csproj b/test/DistEvents/DistDemoApp.Shared/DistDemoApp.Shared.csproj index 4f5cb8ad84..f43d82dd19 100644 --- a/test/DistEvents/DistDemoApp.Shared/DistDemoApp.Shared.csproj +++ b/test/DistEvents/DistDemoApp.Shared/DistDemoApp.Shared.csproj @@ -17,7 +17,7 @@ - + diff --git a/test/DistEvents/DistDemoApp.Shared/DistDemoAppSharedModule.cs b/test/DistEvents/DistDemoApp.Shared/DistDemoAppSharedModule.cs index 138b64f567..936264e828 100644 --- a/test/DistEvents/DistDemoApp.Shared/DistDemoAppSharedModule.cs +++ b/test/DistEvents/DistDemoApp.Shared/DistDemoAppSharedModule.cs @@ -5,7 +5,7 @@ using StackExchange.Redis; using Volo.Abp.Autofac; using Volo.Abp.Domain; using Volo.Abp.Domain.Entities.Events.Distributed; -using Volo.Abp.EventBus.Boxes; +using Volo.Abp.EventBus; using Volo.Abp.Modularity; namespace DistDemoApp @@ -13,8 +13,8 @@ namespace DistDemoApp [DependsOn( typeof(AbpAutofacModule), typeof(AbpDddDomainModule), - typeof(AbpEventBusBoxesModule) - )] + typeof(AbpEventBusModule) + )] public class DistDemoAppSharedModule : AbpModule { public override void ConfigureServices(ServiceConfigurationContext context) @@ -28,7 +28,7 @@ namespace DistDemoApp options.EtoMappings.Add(); options.AutoEventSelectors.Add(); }); - + context.Services.AddSingleton(sp => { var connection = ConnectionMultiplexer.Connect(configuration["Redis:Configuration"]); @@ -36,4 +36,4 @@ namespace DistDemoApp }); } } -} \ No newline at end of file +}