diff --git a/framework/src/Volo.Abp.AspNetCore/Microsoft/AspNetCore/Builder/AbpApplicationBuilderExtensions.cs b/framework/src/Volo.Abp.AspNetCore/Microsoft/AspNetCore/Builder/AbpApplicationBuilderExtensions.cs index 22c0079571..033fef813f 100644 --- a/framework/src/Volo.Abp.AspNetCore/Microsoft/AspNetCore/Builder/AbpApplicationBuilderExtensions.cs +++ b/framework/src/Volo.Abp.AspNetCore/Microsoft/AspNetCore/Builder/AbpApplicationBuilderExtensions.cs @@ -2,6 +2,7 @@ using JetBrains.Annotations; using Microsoft.AspNetCore.RequestLocalization; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; using Volo.Abp; using Volo.Abp.AspNetCore.Auditing; using Volo.Abp.AspNetCore.ExceptionHandling; @@ -19,8 +20,21 @@ namespace Microsoft.AspNetCore.Builder { Check.NotNull(app, nameof(app)); + var application = app.ApplicationServices.GetRequiredService(); + var applicationLifetime = app.ApplicationServices.GetRequiredService(); + + applicationLifetime.ApplicationStopping.Register(() => + { + application.Shutdown(); + }); + + applicationLifetime.ApplicationStopped.Register(() => + { + application.Dispose(); + }); + app.ApplicationServices.GetRequiredService>().Value = app; - app.ApplicationServices.GetRequiredService().Initialize(app.ApplicationServices); + application.Initialize(app.ApplicationServices); } public static IApplicationBuilder UseAuditing(this IApplicationBuilder app) @@ -42,7 +56,8 @@ namespace Microsoft.AspNetCore.Builder .UseMiddleware(); } - public static IApplicationBuilder UseAbpRequestLocalization(this IApplicationBuilder app, Action optionsAction = null) + public static IApplicationBuilder UseAbpRequestLocalization(this IApplicationBuilder app, + Action optionsAction = null) { app.ApplicationServices .GetRequiredService() @@ -62,4 +77,4 @@ namespace Microsoft.AspNetCore.Builder return app.UseMiddleware(); } } -} +} \ No newline at end of file