reduce duplication
This commit is contained in:
@@ -6,6 +6,7 @@ using Smidge;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Hosting;
|
||||
using Umbraco.Extensions;
|
||||
using Umbraco.Infrastructure.Logging.Serilog.Enrichers;
|
||||
using Umbraco.Web.Common.Middleware;
|
||||
|
||||
@@ -17,9 +18,7 @@ namespace Umbraco.Web.BackOffice.AspNetCore
|
||||
{
|
||||
if (app == null) throw new ArgumentNullException(nameof(app));
|
||||
|
||||
var runtime = app.ApplicationServices.GetRequiredService<IRuntime>();
|
||||
// can't continue if boot failed
|
||||
if (runtime.State.Level <= RuntimeLevel.BootFailed) return app;
|
||||
if (!app.UmbracoCanBoot()) return app;
|
||||
|
||||
// TODO: start the back office
|
||||
|
||||
@@ -35,10 +34,10 @@ namespace Umbraco.Web.BackOffice.AspNetCore
|
||||
{
|
||||
if (app == null) throw new ArgumentNullException(nameof(app));
|
||||
|
||||
var runtime = app.ApplicationServices.GetRequiredService<IRuntime>();
|
||||
|
||||
if (runtime.State.Level > RuntimeLevel.BootFailed)
|
||||
if (app.UmbracoCanBoot())
|
||||
{
|
||||
var runtime = app.ApplicationServices.GetRequiredService<IRuntime>();
|
||||
|
||||
// Register a listener for application shutdown in order to terminate the runtime
|
||||
var hostLifetime = app.ApplicationServices.GetRequiredService<IApplicationShutdownRegistry>();
|
||||
var runtimeShutdown = new CoreRuntimeShutdown(runtime, hostLifetime);
|
||||
@@ -53,7 +52,8 @@ namespace Umbraco.Web.BackOffice.AspNetCore
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO: Register simple middleware to show the error like we used to in UmbracoModule?
|
||||
// TODO: Register simple middleware to show the error like we used to in UmbracoModule? Or maybe that's part of a UseUmbracoWebsite/backoffice type thing .. probably :)
|
||||
|
||||
}
|
||||
|
||||
return app;
|
||||
@@ -90,9 +90,7 @@ namespace Umbraco.Web.BackOffice.AspNetCore
|
||||
{
|
||||
if (app == null) throw new ArgumentNullException(nameof(app));
|
||||
|
||||
var runtime = app.ApplicationServices.GetRequiredService<IRuntime>();
|
||||
// can't continue if boot failed
|
||||
if (runtime.State.Level <= RuntimeLevel.BootFailed) return app;
|
||||
if (!app.UmbracoCanBoot()) return app;
|
||||
|
||||
app.UseMiddleware<UmbracoRequestLoggingMiddleware>();
|
||||
|
||||
@@ -103,9 +101,7 @@ namespace Umbraco.Web.BackOffice.AspNetCore
|
||||
{
|
||||
if (app == null) throw new ArgumentNullException(nameof(app));
|
||||
|
||||
var runtime = app.ApplicationServices.GetRequiredService<IRuntime>();
|
||||
// can't continue if boot failed
|
||||
if (runtime.State.Level <= RuntimeLevel.BootFailed) return app;
|
||||
if (!app.UmbracoCanBoot()) return app;
|
||||
|
||||
app.UseSmidge();
|
||||
|
||||
|
||||
@@ -7,16 +7,21 @@ using Umbraco.Web.Common.Middleware;
|
||||
|
||||
namespace Umbraco.Extensions
|
||||
{
|
||||
public static class UmbracoRequestApplicationBuilderExtensions
|
||||
public static class UmbracoCommonApplicationBuilderExtensions
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
// 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)
|
||||
{
|
||||
if (app == null) throw new ArgumentNullException(nameof(app));
|
||||
|
||||
var runtime = app.ApplicationServices.GetRequiredService<IRuntime>();
|
||||
// can't continue if boot failed
|
||||
if (runtime.State.Level <= RuntimeLevel.BootFailed) return app;
|
||||
if (!app.UmbracoCanBoot()) return app;
|
||||
|
||||
app.UseMiddleware<UmbracoRequestMiddleware>();
|
||||
app.UseMiddleware<MiniProfilerMiddleware>();
|
||||
@@ -3,6 +3,7 @@ using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using SixLabors.ImageSharp.Web.DependencyInjection;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Extensions;
|
||||
|
||||
namespace Umbraco.Web.Website.AspNetCore
|
||||
{
|
||||
@@ -12,10 +13,7 @@ namespace Umbraco.Web.Website.AspNetCore
|
||||
{
|
||||
if (app == null) throw new ArgumentNullException(nameof(app));
|
||||
|
||||
var runtime = app.ApplicationServices.GetRequiredService<IRuntime>();
|
||||
|
||||
// can't continue if boot failed
|
||||
if (runtime.State.Level <= RuntimeLevel.BootFailed) return app;
|
||||
if (!app.UmbracoCanBoot()) return app;
|
||||
|
||||
// Important we handle image manipulations before the static files, otherwise the querystring is just ignored.
|
||||
app.UseImageSharp();
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Umbraco.Core\Umbraco.Core.csproj" />
|
||||
<ProjectReference Include="..\Umbraco.Infrastructure\Umbraco.Infrastructure.csproj" />
|
||||
<ProjectReference Include="..\Umbraco.Web.Common\Umbraco.Web.Common.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
Reference in New Issue
Block a user