| | | 1 | | using Microsoft.Extensions.DependencyInjection; |
| | | 2 | | |
| | | 3 | | namespace Allyaria.Theming.Extensions; |
| | | 4 | | |
| | | 5 | | /// <summary> |
| | | 6 | | /// Provides extension methods for registering Allyaria theming services within a dependency injection (DI) container. |
| | | 7 | | /// </summary> |
| | | 8 | | /// <remarks> |
| | | 9 | | /// This class enables consumers to configure and register the Allyaria theming system by supplying an optional |
| | | 10 | | /// <see cref="Brand" />, an initial <see cref="ThemeType" />, and optional <see cref="IThemeConfigurator" /> overrides |
| | | 11 | | /// during service setup. |
| | | 12 | | /// </remarks> |
| | | 13 | | public static class ServiceCollectionExtensions |
| | | 14 | | { |
| | | 15 | | /// <summary> |
| | | 16 | | /// Adds and configures the Allyaria theming service for the application’s dependency injection container. |
| | | 17 | | /// </summary> |
| | | 18 | | /// <param name="services">The <see cref="IServiceCollection" /> to which the theming service will be added.</param> |
| | | 19 | | /// <param name="brand"> |
| | | 20 | | /// An optional <see cref="Brand" /> instance defining the font and theme variants for the application. If null, a n |
| | | 21 | | /// default <see cref="Brand" /> will be created. |
| | | 22 | | /// </param> |
| | | 23 | | /// <param name="initialThemeType"> |
| | | 24 | | /// The initial <see cref="ThemeType" /> to apply (e.g., Light, Dark, System, or HighContrast). Defaults to |
| | | 25 | | /// <see cref="ThemeType.System" />. |
| | | 26 | | /// </param> |
| | | 27 | | /// <param name="overrides"> |
| | | 28 | | /// An optional <see cref="IThemeConfigurator" /> providing additional or replacement <see cref="ThemeUpdater" /> in |
| | | 29 | | /// for fine-grained theme customization. |
| | | 30 | | /// </param> |
| | | 31 | | /// <returns>The same <see cref="IServiceCollection" /> instance, allowing for method chaining.</returns> |
| | | 32 | | public static IServiceCollection AddAllyariaTheming(this IServiceCollection services, |
| | | 33 | | Brand? brand = null, |
| | | 34 | | ThemeType initialThemeType = ThemeType.System, |
| | | 35 | | IThemeConfigurator? overrides = null) |
| | | 36 | | { |
| | 3 | 37 | | services.AddScoped<IThemingService>( |
| | 3 | 38 | | implementationFactory: _ => |
| | 3 | 39 | | { |
| | 4 | 40 | | var builder = new ThemeBuilder().Create(brand: brand ?? new Brand()); |
| | 3 | 41 | | |
| | 4 | 42 | | if (overrides is not null) |
| | 3 | 43 | | { |
| | 4 | 44 | | foreach (var updater in overrides) |
| | 3 | 45 | | { |
| | 1 | 46 | | builder.Set(updater: updater); |
| | 3 | 47 | | } |
| | 3 | 48 | | } |
| | 3 | 49 | | |
| | 4 | 50 | | var theme = builder.Build(); |
| | 3 | 51 | | |
| | 4 | 52 | | return new ThemingService(theme: theme, themeType: initialThemeType); |
| | 3 | 53 | | } |
| | 3 | 54 | | ); |
| | | 55 | | |
| | 3 | 56 | | return services; |
| | | 57 | | } |
| | | 58 | | } |