< Summary

Information
Class: MyNet.Globalization.Facade.GlobalizationServices
Assembly: MyNet.Globalization
File(s): https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.Globalization/Facade/GlobalizationServices.cs
Tag: 323_28699572109
Line coverage
100%
Covered lines: 10
Uncovered lines: 0
Coverable lines: 10
Total lines: 51
Line coverage: 100%
Branch coverage
100%
Covered branches: 2
Total branches: 2
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.cctor()100%11100%
Configure(...)100%22100%
get_Current()100%11100%
CreateDefaultGlobalization()100%11100%

File(s)

https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.Globalization/Facade/GlobalizationServices.cs

#LineLine coverage
 1// -----------------------------------------------------------------------
 2// <copyright file="GlobalizationServices.cs" company="Stéphane ANDRE">
 3// Copyright (c) Stéphane ANDRE. All rights reserved.
 4// </copyright>
 5// -----------------------------------------------------------------------
 6
 7using System;
 8using System.Threading;
 9using MyNet.Globalization.Culture;
 10using MyNet.Globalization.DateTime;
 11
 12namespace MyNet.Globalization.Facade;
 13
 14/// <summary>
 15/// Provides static access to globalization-related services.
 16/// </summary>
 17public static class GlobalizationServices
 18{
 919    private static readonly GlobalizationServiceProxy CurrentProxy = new(CreateDefaultGlobalization());
 20
 21    private static int _configured;
 22
 23    /// <summary>
 24    /// Configures the globalization services by providing an <see cref="IServiceProvider"/>.
 25    /// Call this once during application startup after building the DI container.
 26    /// </summary>
 27    public static void Configure(IGlobalizationService globalization)
 28    {
 929        ArgumentNullException.ThrowIfNull(globalization);
 30
 931        if (Interlocked.Exchange(ref _configured, 1) == 1)
 332            return;
 33
 634        CurrentProxy.SetTarget(globalization);
 635    }
 36
 37    /// <summary>
 38    /// Gets the combined <see cref="IGlobalizationService"/> providing both culture and time zone management.
 39    /// The returned instance is stable for the application lifetime; <see cref="Configure"/> only replaces its target.
 40    /// </summary>
 592841    public static IGlobalizationService Current => CurrentProxy;
 42
 43    private static GlobalizationService CreateDefaultGlobalization()
 44    {
 945        CultureService defaultCultureService = new();
 946        TimeZoneService defaultTimeZoneService = new();
 47
 948        return new(defaultCultureService, defaultTimeZoneService);
 49    }
 50}
 51