2018-04-18 19:46:47 +02:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Concurrent;
|
|
|
|
|
|
using System.Threading;
|
|
|
|
|
|
|
2021-02-18 11:06:02 +01:00
|
|
|
|
namespace Umbraco.Cms.Core.Models.PublishedContent
|
2018-04-18 19:46:47 +02:00
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
2018-04-30 21:29:49 +02:00
|
|
|
|
/// Provides a CurrentUICulture-based implementation of <see cref="IVariationContextAccessor"/>.
|
2018-04-18 19:46:47 +02:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <remarks>
|
|
|
|
|
|
/// <para>This accessor does not support segments. There is no need to set the current context.</para>
|
|
|
|
|
|
/// </remarks>
|
2018-04-30 21:29:49 +02:00
|
|
|
|
public class ThreadCultureVariationContextAccessor : IVariationContextAccessor
|
2018-04-18 19:46:47 +02:00
|
|
|
|
{
|
2018-04-30 21:29:49 +02:00
|
|
|
|
private readonly ConcurrentDictionary<string, VariationContext> _contexts = new ConcurrentDictionary<string, VariationContext>();
|
2018-04-18 19:46:47 +02:00
|
|
|
|
|
2022-01-21 11:43:58 +01:00
|
|
|
|
public VariationContext? VariationContext
|
2018-04-18 19:46:47 +02:00
|
|
|
|
{
|
2018-04-30 21:29:49 +02:00
|
|
|
|
get => _contexts.GetOrAdd(Thread.CurrentThread.CurrentUICulture.Name, culture => new VariationContext(culture));
|
2018-04-18 19:46:47 +02:00
|
|
|
|
set => throw new NotSupportedException();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-04-30 21:03:43 +02:00
|
|
|
|
}
|