Listen IHostApplicationLifetime Stopping and Stopped event.

pull/2528/head
Mehmet Tüken 6 years ago
parent 908f28297a
commit bf1960213f

@ -2,6 +2,7 @@
using JetBrains.Annotations; using JetBrains.Annotations;
using Microsoft.AspNetCore.RequestLocalization; using Microsoft.AspNetCore.RequestLocalization;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Volo.Abp; using Volo.Abp;
using Volo.Abp.AspNetCore.Auditing; using Volo.Abp.AspNetCore.Auditing;
using Volo.Abp.AspNetCore.ExceptionHandling; using Volo.Abp.AspNetCore.ExceptionHandling;
@ -19,8 +20,21 @@ namespace Microsoft.AspNetCore.Builder
{ {
Check.NotNull(app, nameof(app)); Check.NotNull(app, nameof(app));
var application = app.ApplicationServices.GetRequiredService<IAbpApplicationWithExternalServiceProvider>();
var applicationLifetime = app.ApplicationServices.GetRequiredService<IHostApplicationLifetime>();
applicationLifetime.ApplicationStopping.Register(() =>
{
application.Shutdown();
});
applicationLifetime.ApplicationStopped.Register(() =>
{
application.Dispose();
});
app.ApplicationServices.GetRequiredService<ObjectAccessor<IApplicationBuilder>>().Value = app; app.ApplicationServices.GetRequiredService<ObjectAccessor<IApplicationBuilder>>().Value = app;
app.ApplicationServices.GetRequiredService<IAbpApplicationWithExternalServiceProvider>().Initialize(app.ApplicationServices); application.Initialize(app.ApplicationServices);
} }
public static IApplicationBuilder UseAuditing(this IApplicationBuilder app) public static IApplicationBuilder UseAuditing(this IApplicationBuilder app)
@ -42,7 +56,8 @@ namespace Microsoft.AspNetCore.Builder
.UseMiddleware<AbpCorrelationIdMiddleware>(); .UseMiddleware<AbpCorrelationIdMiddleware>();
} }
public static IApplicationBuilder UseAbpRequestLocalization(this IApplicationBuilder app, Action<RequestLocalizationOptions> optionsAction = null) public static IApplicationBuilder UseAbpRequestLocalization(this IApplicationBuilder app,
Action<RequestLocalizationOptions> optionsAction = null)
{ {
app.ApplicationServices app.ApplicationServices
.GetRequiredService<IAbpRequestLocalizationOptionsProvider>() .GetRequiredService<IAbpRequestLocalizationOptionsProvider>()
@ -62,4 +77,4 @@ namespace Microsoft.AspNetCore.Builder
return app.UseMiddleware<AbpExceptionHandlingMiddleware>(); return app.UseMiddleware<AbpExceptionHandlingMiddleware>();
} }
} }
} }
Loading…
Cancel
Save