Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct the order of module configurations #16227

Merged
merged 7 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/OrchardCore.Modules/OrchardCore.Admin/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
5 changes: 3 additions & 2 deletions src/OrchardCore.Modules/OrchardCore.Cors/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@

namespace OrchardCore.Cors
{
public class Startup : StartupBase
public sealed 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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public Startup(IShellConfiguration configuration, ILogger<Startup> logger)
}

// Assume that this module will override default configuration, so set the Order to a value above the default.
Piedone marked this conversation as resolved.
Show resolved Hide resolved
public override int Order => 10;
public override int Order
=> OrchardCoreConstants.ConfigureOrder.AzureDataProtection;

public override void ConfigureServices(IServiceCollection services)
{
Expand Down
3 changes: 2 additions & 1 deletion src/OrchardCore.Modules/OrchardCore.HomeRoute/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
5 changes: 2 additions & 3 deletions src/OrchardCore.Modules/OrchardCore.Media.AmazonS3/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.ImageSharpCache;

public override void ConfigureServices(IServiceCollection services)
{
Expand Down
8 changes: 4 additions & 4 deletions src/OrchardCore.Modules/OrchardCore.Media.Azure/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ public Startup(ILogger<Startup> 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)
{
Expand Down Expand Up @@ -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.AzureImageSharpCache;

public override void ConfigureServices(IServiceCollection services)
{
Expand Down
10 changes: 0 additions & 10 deletions src/OrchardCore.Modules/OrchardCore.Media/MediaConstants.cs

This file was deleted.

3 changes: 2 additions & 1 deletion src/OrchardCore.Modules/OrchardCore.Media/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down
8 changes: 4 additions & 4 deletions src/OrchardCore.Modules/OrchardCore.ReverseProxy/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace OrchardCore.Modules
public abstract class StartupBase : IStartup, IAsyncStartup
{
/// <inheritdoc />
public virtual int Order { get; }
public virtual int Order { get; } = OrchardCoreConstants.ConfigureOrder.Default;

/// <inheritdoc />
public virtual int ConfigureOrder => Order;
Expand Down
40 changes: 40 additions & 0 deletions src/OrchardCore/OrchardCore.Abstractions/OrchardCoreConstants.cs
Piedone marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -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;
MikeAlhayek marked this conversation as resolved.
Show resolved Hide resolved

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 ImageSharpCache = Media + 5;

// Image cache overrides Media configurations and services.
// The order number should always be greater than Media module.
public const int AzureImageSharpCache = 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;
MikeAlhayek marked this conversation as resolved.
Show resolved Hide resolved

public const int AdminPages = 1000;

// Services that should always be registered before everything else.
public const int InfrastructureService = int.MinValue + 100;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ sd is ClonedSingletonDescriptor &&

collection.AddMetrics();
},
order: int.MinValue + 100);
order: OrchardCoreConstants.ConfigureOrder.InfrastructureService);
}

/// <summary>
Expand Down Expand Up @@ -339,7 +339,7 @@ private static void AddRouting(OrchardCoreBuilder builder)

collection.AddRouting();
},
order: int.MinValue + 100);
order: OrchardCoreConstants.ConfigureOrder.InfrastructureService);
}

/// <summary>
Expand Down Expand Up @@ -378,7 +378,7 @@ sd is ClonedSingletonDescriptor &&
collection.AddSingleton<IHttpClientFactory>(sp => sp.GetRequiredService<TenantHttpClientFactory>());
collection.AddSingleton<IHttpMessageHandlerFactory>(sp => sp.GetRequiredService<TenantHttpClientFactory>());
},
order: int.MinValue + 100);
order: OrchardCoreConstants.ConfigureOrder.InfrastructureService);
}

/// <summary>
Expand Down Expand Up @@ -407,7 +407,7 @@ sd is ClonedSingletonDescriptor &&
// Configure ApiExplorer at the tenant level.
collection.AddEndpointsApiExplorer();
},
order: int.MinValue + 100);
order: OrchardCoreConstants.ConfigureOrder.InfrastructureService);
}

/// <summary>
Expand All @@ -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.
});

Expand Down Expand Up @@ -522,7 +522,7 @@ private static void AddAuthentication(OrchardCoreBuilder builder)
.Configure(app =>
{
app.UseAuthentication();
}, order: -150);
}, order: OrchardCoreConstants.ConfigureOrder.Authentication);
}

/// <summary>
Expand Down Expand Up @@ -557,7 +557,7 @@ private static void AddDataProtection(OrchardCoreBuilder builder)
services.RemoveAll<IConfigureOptions<DataProtectionOptions>>();

services.Add(collection);
});
}, order: OrchardCoreConstants.ConfigureOrder.DataProtection);
}
}
}
6 changes: 3 additions & 3 deletions src/docs/reference/modules/Media/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.

Expand Down Expand Up @@ -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

`<img src="~/media/animals/kittens.jpg?width=100&height=240&rmode=pad&bgcolor=white" />`

Expand Down