| | | 1 | | // ----------------------------------------------------------------------- |
| | | 2 | | // <copyright file="LocalizationFactoryRegistry.cs" company="Stéphane ANDRE"> |
| | | 3 | | // Copyright (c) Stéphane ANDRE. All rights reserved. |
| | | 4 | | // </copyright> |
| | | 5 | | // ----------------------------------------------------------------------- |
| | | 6 | | |
| | | 7 | | using System; |
| | | 8 | | using System.Collections.Frozen; |
| | | 9 | | using System.Collections.Generic; |
| | | 10 | | using System.Diagnostics.CodeAnalysis; |
| | | 11 | | using MyNet.Globalization.Localization.Providers.Factories; |
| | | 12 | | |
| | | 13 | | namespace MyNet.Globalization.Localization.Providers.Registration; |
| | | 14 | | |
| | | 15 | | /// <summary> |
| | | 16 | | /// Current implementation of <see cref="ILocalizationFactoryRegistry"/> that stores factories in a frozen dictionary fo |
| | | 17 | | /// </summary> |
| | | 18 | | /// <param name="factories">The factories to be registered.</param> |
| | | 19 | | public sealed class LocalizationFactoryRegistry(IReadOnlyDictionary<Type, ILocalizationServiceFactory> factories) : ILoc |
| | | 20 | | { |
| | 354 | 21 | | private readonly FrozenDictionary<Type, ILocalizationServiceFactory> _factories = factories.ToFrozenDictionary(); |
| | | 22 | | |
| | | 23 | | /// <inheritdoc /> |
| | 0 | 24 | | public IReadOnlyDictionary<Type, ILocalizationServiceFactory> Factories => _factories; |
| | | 25 | | |
| | | 26 | | /// <inheritdoc /> |
| | | 27 | | public bool TryGetFactory<TService>([NotNullWhen(true)] out ILocalizationServiceFactory<TService>? factory) |
| | | 28 | | where TService : class, ICultureScoped |
| | | 29 | | { |
| | 126 | 30 | | if (_factories.TryGetValue(typeof(TService), out var obj) && obj is ILocalizationServiceFactory<TService> typedF |
| | | 31 | | { |
| | 126 | 32 | | factory = typedFactory; |
| | 126 | 33 | | return true; |
| | | 34 | | } |
| | | 35 | | |
| | 0 | 36 | | factory = null; |
| | 0 | 37 | | return false; |
| | | 38 | | } |
| | | 39 | | } |
| | | 40 | | |