2021-02-18 11:06:02 +01:00
|
|
|
using Umbraco.Cms.Core.Cache;
|
2018-06-03 17:21:15 +02:00
|
|
|
|
2021-02-18 11:06:02 +01:00
|
|
|
namespace Umbraco.Cms.Core.Models.PublishedContent
|
2018-06-03 17:21:15 +02:00
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Implements <see cref="IVariationContextAccessor"/> on top of <see cref="IHttpContextAccessor"/>.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class HttpContextVariationContextAccessor : IVariationContextAccessor
|
|
|
|
|
{
|
2020-02-13 07:46:49 +01:00
|
|
|
private readonly IRequestCache _requestCache;
|
2020-02-17 08:52:05 +01:00
|
|
|
private const string ContextKey = "Umbraco.Web.Models.PublishedContent.DefaultVariationContextAccessor";
|
2018-06-03 17:21:15 +02:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Initializes a new instance of the <see cref="HttpContextVariationContextAccessor"/> class.
|
|
|
|
|
/// </summary>
|
2021-01-07 22:05:23 +11:00
|
|
|
public HttpContextVariationContextAccessor(IRequestCache requestCache) => _requestCache = requestCache;
|
2018-06-03 17:21:15 +02:00
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public VariationContext VariationContext
|
|
|
|
|
{
|
2020-02-17 08:52:05 +01:00
|
|
|
get => (VariationContext) _requestCache.Get(ContextKey);
|
|
|
|
|
set => _requestCache.Set(ContextKey, value);
|
2018-06-03 17:21:15 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|