< Summary

Information
Class: Allyaria.Theming.Extensions.ServiceCollectionExtensions
Assembly: Allyaria.Theming
File(s): /home/runner/work/allyaria/allyaria/src/Allyaria.Theming/Extensions/ServiceCollectionExtensions.cs
Line coverage
100%
Covered lines: 19
Uncovered lines: 0
Coverable lines: 19
Total lines: 58
Line coverage: 100%
Branch coverage
100%
Covered branches: 6
Total branches: 6
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
AddAllyariaTheming(...)100%66100%

File(s)

/home/runner/work/allyaria/allyaria/src/Allyaria.Theming/Extensions/ServiceCollectionExtensions.cs

#LineLine coverage
 1using Microsoft.Extensions.DependencyInjection;
 2
 3namespace 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>
 13public 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    {
 337        services.AddScoped<IThemingService>(
 338            implementationFactory: _ =>
 339            {
 440                var builder = new ThemeBuilder().Create(brand: brand ?? new Brand());
 341
 442                if (overrides is not null)
 343                {
 444                    foreach (var updater in overrides)
 345                    {
 146                        builder.Set(updater: updater);
 347                    }
 348                }
 349
 450                var theme = builder.Build();
 351
 452                return new ThemingService(theme: theme, themeType: initialThemeType);
 353            }
 354        );
 55
 356        return services;
 57    }
 58}