| | | 1 | | // ----------------------------------------------------------------------- |
| | | 2 | | // <copyright file="LocalizationServiceContext.cs" company="Stéphane ANDRE"> |
| | | 3 | | // Copyright (c) Stéphane ANDRE. All rights reserved. |
| | | 4 | | // </copyright> |
| | | 5 | | // ----------------------------------------------------------------------- |
| | | 6 | | |
| | | 7 | | using System; |
| | | 8 | | using System.Diagnostics.CodeAnalysis; |
| | | 9 | | using System.Globalization; |
| | | 10 | | |
| | | 11 | | namespace MyNet.Globalization.Localization.Providers; |
| | | 12 | | |
| | | 13 | | /// <summary> |
| | | 14 | | /// Current implementation of <see cref="ILocalizationServiceContext"/>. |
| | | 15 | | /// Binds a specific <see cref="Culture"/> to an <see cref="ILocalizationServiceResolver"/>, |
| | | 16 | | /// eliminating the need to pass the culture on every provider resolution call. |
| | | 17 | | /// </summary> |
| | | 18 | | /// <param name="resolver">The underlying provider resolver.</param> |
| | | 19 | | /// <param name="culture">The culture this context is scoped to.</param> |
| | | 20 | | public sealed class LocalizationServiceContext(ILocalizationServiceResolver resolver, CultureInfo culture) : ILocalizati |
| | | 21 | | { |
| | | 22 | | /// <inheritdoc /> |
| | 6723 | 23 | | public CultureInfo Culture { get; } = culture ?? throw new ArgumentNullException(nameof(culture)); |
| | | 24 | | |
| | | 25 | | public bool TryGet<TService>([NotNullWhen(true)] out TService? service) |
| | 0 | 26 | | where TService : class, ICultureScoped => resolver.TryGet(Culture, out service); |
| | | 27 | | |
| | | 28 | | /// <inheritdoc /> |
| | | 29 | | public TService GetRequired<TService>() |
| | 6723 | 30 | | where TService : class, ICultureScoped => resolver.GetRequired<TService>(Culture); |
| | | 31 | | } |
| | | 32 | | |