2020-03-24 18:18:25 +01:00
|
|
|
using System;
|
|
|
|
|
using Microsoft.AspNetCore.Builder;
|
2020-05-08 17:30:30 +10:00
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
2020-03-29 22:35:52 +02:00
|
|
|
using StackExchange.Profiling;
|
2020-05-08 17:30:30 +10:00
|
|
|
using Umbraco.Core;
|
2020-03-24 18:18:25 +01:00
|
|
|
using Umbraco.Web.Common.Middleware;
|
|
|
|
|
|
2020-05-07 10:08:23 +02:00
|
|
|
namespace Umbraco.Extensions
|
2020-03-24 18:18:25 +01:00
|
|
|
{
|
2020-05-08 17:36:59 +10:00
|
|
|
public static class UmbracoCommonApplicationBuilderExtensions
|
2020-03-24 18:18:25 +01:00
|
|
|
{
|
2020-05-08 17:36:59 +10:00
|
|
|
public static bool UmbracoCanBoot(this IApplicationBuilder app)
|
|
|
|
|
{
|
|
|
|
|
var runtime = app.ApplicationServices.GetRequiredService<IRuntime>();
|
|
|
|
|
// can't continue if boot failed
|
|
|
|
|
return runtime.State.Level > RuntimeLevel.BootFailed;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-08 17:30:30 +10:00
|
|
|
// TODO: Could be internal or part of another call - this is a required system so should't be 'opt-in'
|
|
|
|
|
public static IApplicationBuilder UseUmbracoRequestLifetime(this IApplicationBuilder app)
|
2020-03-24 18:18:25 +01:00
|
|
|
{
|
2020-05-08 17:30:30 +10:00
|
|
|
if (app == null) throw new ArgumentNullException(nameof(app));
|
2020-03-24 18:18:25 +01:00
|
|
|
|
2020-05-08 17:36:59 +10:00
|
|
|
if (!app.UmbracoCanBoot()) return app;
|
2020-03-24 18:18:25 +01:00
|
|
|
|
2020-03-29 22:35:52 +02:00
|
|
|
app.UseMiddleware<UmbracoRequestMiddleware>();
|
|
|
|
|
app.UseMiddleware<MiniProfilerMiddleware>();
|
2020-03-24 18:18:25 +01:00
|
|
|
return app;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-03-29 22:35:52 +02:00
|
|
|
|
2020-03-24 18:18:25 +01:00
|
|
|
}
|