Files
Umbraco-CMS/src/Umbraco.Core/Models/PublishedContent/ThreadCultureVariationContextAccessor.cs

24 lines
898 B
C#
Raw Normal View History

using System;
using System.Collections.Concurrent;
using System.Threading;
namespace Umbraco.Cms.Core.Models.PublishedContent
{
/// <summary>
2018-04-30 21:29:49 +02:00
/// Provides a CurrentUICulture-based implementation of <see cref="IVariationContextAccessor"/>.
/// </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-30 21:29:49 +02:00
private readonly ConcurrentDictionary<string, VariationContext> _contexts = new ConcurrentDictionary<string, VariationContext>();
2018-04-30 21:29:49 +02:00
public VariationContext VariationContext
{
2018-04-30 21:29:49 +02:00
get => _contexts.GetOrAdd(Thread.CurrentThread.CurrentUICulture.Name, culture => new VariationContext(culture));
set => throw new NotSupportedException();
}
}
}