From 4dd9e04382cd7662951337e14cd2a29b671c3e5a Mon Sep 17 00:00:00 2001 From: Mike Alhayek Date: Mon, 3 Jun 2024 13:06:57 -0700 Subject: [PATCH] Correct the order of module configurations Fix #14874 --- .../OrchardCore.Admin/Startup.cs | 3 +- .../OrchardCore.Cors/Startup.cs | 3 +- .../Startup.cs | 3 +- .../OrchardCore.HomeRoute/Startup.cs | 3 +- .../OrchardCore.Media.AmazonS3/Startup.cs | 5 +-- .../OrchardCore.Media.Azure/Startup.cs | 8 ++-- .../OrchardCore.Media/MediaConstants.cs | 10 ----- .../OrchardCore.Media/Startup.cs | 3 +- .../OrchardCore.ReverseProxy/Startup.cs | 8 ++-- .../Modules/StartupBase.cs | 2 +- .../OrchardCoreConstants.cs | 40 +++++++++++++++++++ .../Extensions/ServiceCollectionExtensions.cs | 14 +++---- src/docs/reference/modules/Media/README.md | 6 +-- 13 files changed, 71 insertions(+), 37 deletions(-) delete mode 100644 src/OrchardCore.Modules/OrchardCore.Media/MediaConstants.cs diff --git a/src/OrchardCore.Modules/OrchardCore.Admin/Startup.cs b/src/OrchardCore.Modules/OrchardCore.Admin/Startup.cs index 41178b4f5ad..5bc2fa61a46 100644 --- a/src/OrchardCore.Modules/OrchardCore.Admin/Startup.cs +++ b/src/OrchardCore.Modules/OrchardCore.Admin/Startup.cs @@ -78,7 +78,8 @@ public override void Configure(IApplicationBuilder builder, IEndpointRouteBuilde public class AdminPagesStartup : StartupBase { - public override int Order => 1000; + public override int Order + => OrchardCoreConstants.ConfigureOrder.AdminPages; public override void ConfigureServices(IServiceCollection services) { diff --git a/src/OrchardCore.Modules/OrchardCore.Cors/Startup.cs b/src/OrchardCore.Modules/OrchardCore.Cors/Startup.cs index 5b90899adb4..d69fb239d5e 100644 --- a/src/OrchardCore.Modules/OrchardCore.Cors/Startup.cs +++ b/src/OrchardCore.Modules/OrchardCore.Cors/Startup.cs @@ -15,7 +15,8 @@ namespace OrchardCore.Cors { public class Startup : StartupBase { - public override int Order => -1; + public override int Order + => OrchardCoreConstants.ConfigureOrder.Cors; public override void Configure(IApplicationBuilder app, IEndpointRouteBuilder routes, IServiceProvider serviceProvider) { diff --git a/src/OrchardCore.Modules/OrchardCore.DataProtection.Azure/Startup.cs b/src/OrchardCore.Modules/OrchardCore.DataProtection.Azure/Startup.cs index 084236042b2..0c9d949ee41 100644 --- a/src/OrchardCore.Modules/OrchardCore.DataProtection.Azure/Startup.cs +++ b/src/OrchardCore.Modules/OrchardCore.DataProtection.Azure/Startup.cs @@ -20,7 +20,8 @@ public Startup(IShellConfiguration configuration, ILogger logger) } // Assume that this module will override default configuration, so set the Order to a value above the default. - public override int Order => 10; + public override int Order + => OrchardCoreConstants.ConfigureOrder.AzureDataProtection; public override void ConfigureServices(IServiceCollection services) { diff --git a/src/OrchardCore.Modules/OrchardCore.HomeRoute/Startup.cs b/src/OrchardCore.Modules/OrchardCore.HomeRoute/Startup.cs index 61fff7d8c64..805d81e5c3e 100644 --- a/src/OrchardCore.Modules/OrchardCore.HomeRoute/Startup.cs +++ b/src/OrchardCore.Modules/OrchardCore.HomeRoute/Startup.cs @@ -10,7 +10,8 @@ namespace OrchardCore.HomeRoute { public class Startup : StartupBase { - public override int Order => -150; + public override int Order + => OrchardCoreConstants.ConfigureOrder.HomeRoute; public override void ConfigureServices(IServiceCollection services) { diff --git a/src/OrchardCore.Modules/OrchardCore.Media.AmazonS3/Startup.cs b/src/OrchardCore.Modules/OrchardCore.Media.AmazonS3/Startup.cs index 33b8d8cd2a2..e7907d2e2a0 100644 --- a/src/OrchardCore.Modules/OrchardCore.Media.AmazonS3/Startup.cs +++ b/src/OrchardCore.Modules/OrchardCore.Media.AmazonS3/Startup.cs @@ -150,9 +150,8 @@ public ImageSharpAmazonS3CacheStartup( _logger = logger; } - // The order should exceed that of the 'OrchardCore.Media' module to substitute the default implementation of 'IImageCache'. - // there. - public override int Order => Media.MediaConstants.StartupOrder + 5; + public override int Order + => OrchardCoreConstants.ConfigureOrder.ImageSharpImageCache; public override void ConfigureServices(IServiceCollection services) { diff --git a/src/OrchardCore.Modules/OrchardCore.Media.Azure/Startup.cs b/src/OrchardCore.Modules/OrchardCore.Media.Azure/Startup.cs index f7f37542ec4..a7d899a21bf 100644 --- a/src/OrchardCore.Modules/OrchardCore.Media.Azure/Startup.cs +++ b/src/OrchardCore.Modules/OrchardCore.Media.Azure/Startup.cs @@ -36,7 +36,8 @@ public Startup(ILogger logger, IShellConfiguration configuration) _configuration = configuration; } - public override int Order => MediaConstants.StartupOrder + 10; + public override int Order + => OrchardCoreConstants.ConfigureOrder.AzureMediaStorage; public override void ConfigureServices(IServiceCollection services) { @@ -156,9 +157,8 @@ public ImageSharpAzureBlobCacheStartup( _logger = logger; } - // The order should exceed that of the 'OrchardCore.Media' module to substitute the default implementation of 'IImageCache'. - // there. - public override int Order => MediaConstants.StartupOrder + 5; + public override int Order + => OrchardCoreConstants.ConfigureOrder.AzureImageSharpImageCache; public override void ConfigureServices(IServiceCollection services) { diff --git a/src/OrchardCore.Modules/OrchardCore.Media/MediaConstants.cs b/src/OrchardCore.Modules/OrchardCore.Media/MediaConstants.cs deleted file mode 100644 index 3584f67cce2..00000000000 --- a/src/OrchardCore.Modules/OrchardCore.Media/MediaConstants.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace OrchardCore.Media; - -public static class MediaConstants -{ - /// - /// The value the Order set by . If you want to run a Startup class before or after - /// that of the Media module's, you can use this value as the starting point. - /// - public const int StartupOrder = 0; -} diff --git a/src/OrchardCore.Modules/OrchardCore.Media/Startup.cs b/src/OrchardCore.Modules/OrchardCore.Media/Startup.cs index 4c04988f3b5..1d7cb6856e5 100644 --- a/src/OrchardCore.Modules/OrchardCore.Media/Startup.cs +++ b/src/OrchardCore.Modules/OrchardCore.Media/Startup.cs @@ -55,7 +55,8 @@ namespace OrchardCore.Media { public class Startup : StartupBase { - public override int Order => MediaConstants.StartupOrder; + public override int Order + => OrchardCoreConstants.ConfigureOrder.Media; private const string ImageSharpCacheFolder = "is-cache"; diff --git a/src/OrchardCore.Modules/OrchardCore.ReverseProxy/Startup.cs b/src/OrchardCore.Modules/OrchardCore.ReverseProxy/Startup.cs index 83f97488ff3..f709971fd15 100644 --- a/src/OrchardCore.Modules/OrchardCore.ReverseProxy/Startup.cs +++ b/src/OrchardCore.Modules/OrchardCore.ReverseProxy/Startup.cs @@ -16,10 +16,10 @@ namespace OrchardCore.ReverseProxy { - public class Startup : StartupBase + public sealed class Startup : StartupBase { - // we need this to start before other security related initialization logic - public override int Order => -1; + public override int Order + => OrchardCoreConstants.ConfigureOrder.ReverseProxy; public override void Configure(IApplicationBuilder app, IEndpointRouteBuilder routes, IServiceProvider serviceProvider) { @@ -40,7 +40,7 @@ public override void ConfigureServices(IServiceCollection services) } [RequireFeatures("OrchardCore.Deployment")] - public class DeploymentStartup : StartupBase + public sealed class DeploymentStartup : StartupBase { public override void ConfigureServices(IServiceCollection services) { diff --git a/src/OrchardCore/OrchardCore.Abstractions/Modules/StartupBase.cs b/src/OrchardCore/OrchardCore.Abstractions/Modules/StartupBase.cs index 1ef4dd1c455..ace6acf4f6b 100644 --- a/src/OrchardCore/OrchardCore.Abstractions/Modules/StartupBase.cs +++ b/src/OrchardCore/OrchardCore.Abstractions/Modules/StartupBase.cs @@ -9,7 +9,7 @@ namespace OrchardCore.Modules public abstract class StartupBase : IStartup, IAsyncStartup { /// - public virtual int Order { get; } + public virtual int Order { get; } = OrchardCoreConstants.ConfigureOrder.Default; /// public virtual int ConfigureOrder => Order; diff --git a/src/OrchardCore/OrchardCore.Abstractions/OrchardCoreConstants.cs b/src/OrchardCore/OrchardCore.Abstractions/OrchardCoreConstants.cs index 3540798ae63..59aa7567a69 100644 --- a/src/OrchardCore/OrchardCore.Abstractions/OrchardCoreConstants.cs +++ b/src/OrchardCore/OrchardCore.Abstractions/OrchardCoreConstants.cs @@ -28,4 +28,44 @@ public class Roles public const string Anonymous = "Anonymous"; } + + public class ConfigureOrder + { + public const int Default = 0; + + // The configuration for authentication should be set up early, prior to any non-security modules. + public const int Authentication = -150; + + // The reverse proxy should always be configured before the 'Authentication' and security initialization logic. + public const int ReverseProxy = Authentication * 2; + + public const int Cors = ReverseProxy; + + public const int Media = Default; + + // Image cache overrides Media configurations and services. + // The order number should always be greater than Media module. + public const int ImageSharpImageCache = Media + 5; + + // Image cache overrides Media configurations and services. + // The order number should always be greater than Media module. + public const int AzureImageSharpImageCache = Media + 5; + + // Azure media storage overrides Media configurations and services. + // The order number should always be greater than Media module. + public const int AzureMediaStorage = Media + 10; + + public const int DataProtection = Default; + + // Azure DataProtection will override default data-protection configurations. + // The order number should always be greater than data protection modules. + public const int AzureDataProtection = DataProtection + 10; + + public const int HomeRoute = -150; + + public const int AdminPages = 1000; + + // Services that should always be registered before everything else. + public const int InfrastructureService = int.MinValue + 100; + } } diff --git a/src/OrchardCore/OrchardCore/Modules/Extensions/ServiceCollectionExtensions.cs b/src/OrchardCore/OrchardCore/Modules/Extensions/ServiceCollectionExtensions.cs index 7314e21d9e8..3a06108b8e2 100644 --- a/src/OrchardCore/OrchardCore/Modules/Extensions/ServiceCollectionExtensions.cs +++ b/src/OrchardCore/OrchardCore/Modules/Extensions/ServiceCollectionExtensions.cs @@ -308,7 +308,7 @@ sd is ClonedSingletonDescriptor && collection.AddMetrics(); }, - order: int.MinValue + 100); + order: OrchardCoreConstants.ConfigureOrder.InfrastructureService); } /// @@ -339,7 +339,7 @@ private static void AddRouting(OrchardCoreBuilder builder) collection.AddRouting(); }, - order: int.MinValue + 100); + order: OrchardCoreConstants.ConfigureOrder.InfrastructureService); } /// @@ -378,7 +378,7 @@ sd is ClonedSingletonDescriptor && collection.AddSingleton(sp => sp.GetRequiredService()); collection.AddSingleton(sp => sp.GetRequiredService()); }, - order: int.MinValue + 100); + order: OrchardCoreConstants.ConfigureOrder.InfrastructureService); } /// @@ -407,7 +407,7 @@ sd is ClonedSingletonDescriptor && // Configure ApiExplorer at the tenant level. collection.AddEndpointsApiExplorer(); }, - order: int.MinValue + 100); + order: OrchardCoreConstants.ConfigureOrder.InfrastructureService); } /// @@ -429,7 +429,7 @@ private static void AddAntiForgery(OrchardCoreBuilder builder) options.Cookie.Name = cookieName; // Don't set the cookie builder 'Path' so that it uses the 'IAuthenticationFeature' value - // set by the pipeline and comming from the request 'PathBase' which already ends with the + // set by the pipeline and coming from the request 'PathBase' which already ends with the // tenant prefix but may also start by a path related e.g to a virtual folder. }); @@ -522,7 +522,7 @@ private static void AddAuthentication(OrchardCoreBuilder builder) .Configure(app => { app.UseAuthentication(); - }, order: -150); + }, order: OrchardCoreConstants.ConfigureOrder.Authentication); } /// @@ -557,7 +557,7 @@ private static void AddDataProtection(OrchardCoreBuilder builder) services.RemoveAll>(); services.Add(collection); - }); + }, order: OrchardCoreConstants.ConfigureOrder.DataProtection); } } } diff --git a/src/docs/reference/modules/Media/README.md b/src/docs/reference/modules/Media/README.md index bc518964431..49a5a8a4f00 100644 --- a/src/docs/reference/modules/Media/README.md +++ b/src/docs/reference/modules/Media/README.md @@ -118,7 +118,7 @@ The quality used when compressing the image. #### `format` (or fifth argument) -The image format to use when processing the ouput of an image. +The image format to use when processing the output of an image. Supported formats include `bmp`, `gif`, `jpg`, `png`, `tga`. @@ -151,13 +151,13 @@ The anchor of the new image. The background color of the new image when `mode` is `pad` or `boxpad`. Examples of valid values: `white`, `ffff00`, `ffff0080`, `128,64,32` and `128,64,32,16`. -#### bgcolor Input +#### `bgcolor` Input ``` {{ 'animals/kittens.jpg' | asset_url | resize_url: width:100, height:240, mode:'pad', bgcolor:'white' }} ``` -#### bgcolor Output +#### `bgcolor` Output ``