2018-04-18 19:46:47 +02:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Concurrent;
|
|
|
|
|
|
using System.Threading;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Core.Models.PublishedContent
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
2018-04-29 20:02:38 +02:00
|
|
|
|
/// Provides a CurrentUICulture-based implementation of <see cref="ICurrentVariationAccessor"/>.
|
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-29 20:02:38 +02:00
|
|
|
|
public class ThreadCultureCurrentVariationAccessor : ICurrentVariationAccessor
|
2018-04-18 19:46:47 +02:00
|
|
|
|
{
|
2018-04-29 20:02:38 +02:00
|
|
|
|
private readonly ConcurrentDictionary<string, CurrentVariation> _contexts = new ConcurrentDictionary<string, CurrentVariation>();
|
2018-04-18 19:46:47 +02:00
|
|
|
|
|
2018-04-29 20:02:38 +02:00
|
|
|
|
public CurrentVariation CurrentVariation
|
2018-04-18 19:46:47 +02:00
|
|
|
|
{
|
2018-04-29 20:02:38 +02:00
|
|
|
|
get => _contexts.GetOrAdd(Thread.CurrentThread.CurrentUICulture.Name, culture => new CurrentVariation { Culture = culture });
|
2018-04-18 19:46:47 +02:00
|
|
|
|
set => throw new NotSupportedException();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|