Skip to content

Commit

Permalink
Add PrepareShapeTable.
Browse files Browse the repository at this point in the history
  • Loading branch information
sarahelsaig committed Jul 16, 2024
1 parent ef2b6ba commit da2f829
Showing 1 changed file with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -46,4 +49,24 @@ public static IServiceCollection AddInlineStartup(
Func<IApplicationBuilder, IEndpointRouteBuilder, IServiceProvider, ValueTask>? configureAsync = null,
int order = 0) =>
services.AddSingleton<IStartup>(new InlineStartup(configureServices, configure, configureAsync, order));

/// <summary>
/// Registers an <see cref="IStartup"/> implementation that prepares the shape table for the current site and admin
/// themes. The <see cref="IStartup.Order"/> is the maximum possible value, ensuring that this will be executed
/// right before the site starts serving.
/// </summary>
public static IServiceCollection PrepareShapeTable(this IServiceCollection services) =>
services.AddInlineStartup(
configureAsync: async (_, _, serviceProvider) =>
{
var shapeTableManager = serviceProvider.GetRequiredService<IShapeTableManager>();
var siteTheme = await serviceProvider.GetRequiredService<IThemeManager>().GetThemeAsync();
var adminTheme = await serviceProvider.GetRequiredService<IAdminThemeService>().GetAdminThemeAsync();
await shapeTableManager.GetShapeTableAsync(themeId: null);
await shapeTableManager.GetShapeTableAsync(siteTheme.Id);
await shapeTableManager.GetShapeTableAsync(adminTheme.Id);
},
order: int.MaxValue);
}

0 comments on commit da2f829

Please sign in to comment.