< Summary

Information
Class: TeleFlow.Telegram.I18n.Fluent.TelegramFluentI18nServiceCollectionExtensions
Assembly: TeleFlow.Framework.I18n.Fluent
File(s): /_/src/TeleFlow.Framework.I18n.Fluent/TelegramFluentI18nServiceCollectionExtensions.cs
Line coverage
82%
Covered lines: 14
Uncovered lines: 3
Coverable lines: 17
Total lines: 49
Line coverage: 82.3%
Branch coverage
50%
Covered branches: 4
Total branches: 8
Branch coverage: 50%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
AddTelegramFluentI18n(...)50%8882.35%

File(s)

/_/src/TeleFlow.Framework.I18n.Fluent/TelegramFluentI18nServiceCollectionExtensions.cs

#LineLine coverage
 1using Microsoft.Extensions.DependencyInjection;
 2using Microsoft.Extensions.DependencyInjection.Extensions;
 3using TeleFlow.Framework.Application;
 4using TeleFlow.Telegram.I18n.Fluent.Internal;
 5
 6namespace TeleFlow.Telegram.I18n.Fluent;
 7
 8/// <summary>
 9/// Registers startup-loaded Project Fluent catalogs, scoped update localization, and explicit-locale formatting.
 10/// </summary>
 11public static class TelegramFluentI18nServiceCollectionExtensions
 12{
 13    /// <summary>
 14    /// Adds Telegram locale resolution and the Linguini-backed Fluent adapter as optional framework services.
 15    /// </summary>
 16    public static IServiceCollection AddTelegramFluentI18n(
 17        this IServiceCollection services,
 18        Action<TelegramFluentI18nOptions>? configure = null)
 19    {
 2420        ArgumentNullException.ThrowIfNull(services);
 21
 60022        if (services.Any(static descriptor => descriptor.ServiceType == typeof(TelegramFluentI18nOptions)))
 23        {
 024            throw new InvalidOperationException($"{nameof(AddTelegramFluentI18n)} cannot be called more than once.");
 25        }
 26
 2427        var options = new TelegramFluentI18nOptions();
 2428        configure?.Invoke(options);
 29
 2430        if (string.IsNullOrWhiteSpace(options.ResourcesPath))
 31        {
 032            throw new InvalidOperationException("Fluent resource path must not be empty.");
 33        }
 34
 2435        if (options.FallbackLocale is null)
 36        {
 037            throw new InvalidOperationException("Fluent fallback locale must be configured.");
 38        }
 39
 4840        services.AddTelegramI18n(i18n => i18n.FallbackLocale = options.FallbackLocale);
 2441        services.AddSingleton(options);
 2442        services.AddSingleton<FluentCatalog>();
 2443        services.AddSingleton<IFluentTextFormatter, FluentTextFormatter>();
 2444        services.AddScoped<IFluentLocalizer, FluentLocalizer>();
 2445        services.TryAddEnumerable(
 2446            ServiceDescriptor.Singleton<ITeleFlowRuntimeValidator, FluentCatalogRuntimeValidator>());
 2447        return services;
 48    }
 49}