diff --git a/Lombiq.HelpfulLibraries.OrchardCore/DependencyInjection/ServiceCollectionExtensions.cs b/Lombiq.HelpfulLibraries.OrchardCore/DependencyInjection/ServiceCollectionExtensions.cs index 6f5115f1..83b09a57 100644 --- a/Lombiq.HelpfulLibraries.OrchardCore/DependencyInjection/ServiceCollectionExtensions.cs +++ b/Lombiq.HelpfulLibraries.OrchardCore/DependencyInjection/ServiceCollectionExtensions.cs @@ -5,6 +5,9 @@ using Microsoft.AspNetCore.Routing; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; +using OrchardCore.Admin; +using OrchardCore.DisplayManagement.Descriptors; +using OrchardCore.DisplayManagement.Theming; using OrchardCore.Modules; using System; using System.Threading.Tasks; @@ -46,4 +49,24 @@ public static IServiceCollection AddInlineStartup( Func? configureAsync = null, int order = 0) => services.AddSingleton(new InlineStartup(configureServices, configure, configureAsync, order)); + + /// + /// Registers an implementation that prepares the shape table for the current site and admin + /// themes. The is the maximum possible value, ensuring that this will be executed + /// right before the site starts serving. + /// + public static IServiceCollection PrepareShapeTable(this IServiceCollection services) => + services.AddInlineStartup( + configureAsync: async (_, _, serviceProvider) => + { + var shapeTableManager = serviceProvider.GetRequiredService(); + + var siteTheme = await serviceProvider.GetRequiredService().GetThemeAsync(); + var adminTheme = await serviceProvider.GetRequiredService().GetAdminThemeAsync(); + + await shapeTableManager.GetShapeTableAsync(themeId: null); + await shapeTableManager.GetShapeTableAsync(siteTheme.Id); + await shapeTableManager.GetShapeTableAsync(adminTheme.Id); + }, + order: int.MaxValue); }