Skip to content

Commit c799d9e

Browse files
committed
#11123 initializing the IVariationContextAccessor if the UmbracoRequestMiddleware
1 parent f96c6be commit c799d9e

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/Umbraco.Web.Common/Middleware/UmbracoRequestMiddleware.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@
1313
using Umbraco.Cms.Core.Events;
1414
using Umbraco.Cms.Core.Hosting;
1515
using Umbraco.Cms.Core.Logging;
16+
using Umbraco.Cms.Core.Models.PublishedContent;
1617
using Umbraco.Cms.Core.Notifications;
18+
using Umbraco.Cms.Core.PublishedCache;
1719
using Umbraco.Cms.Core.Routing;
1820
using Umbraco.Cms.Core.Scoping;
19-
using Umbraco.Cms.Core.Security;
2021
using Umbraco.Cms.Core.Services;
2122
using Umbraco.Cms.Core.Web;
2223
using Umbraco.Cms.Infrastructure.PublishedCache;
@@ -50,6 +51,8 @@ public class UmbracoRequestMiddleware : IMiddleware
5051
private readonly UmbracoRequestPaths _umbracoRequestPaths;
5152
private readonly BackOfficeWebAssets _backOfficeWebAssets;
5253
private readonly IRuntimeState _runtimeState;
54+
private readonly IVariationContextAccessor _variationContextAccessor;
55+
private readonly IDefaultCultureAccessor _defaultCultureAccessor;
5356
private readonly SmidgeOptions _smidgeOptions;
5457
private readonly WebProfiler _profiler;
5558

@@ -77,7 +80,9 @@ public UmbracoRequestMiddleware(
7780
UmbracoRequestPaths umbracoRequestPaths,
7881
BackOfficeWebAssets backOfficeWebAssets,
7982
IOptions<SmidgeOptions> smidgeOptions,
80-
IRuntimeState runtimeState)
83+
IRuntimeState runtimeState,
84+
IVariationContextAccessor variationContextAccessor,
85+
IDefaultCultureAccessor defaultCultureAccessor)
8186
{
8287
_logger = logger;
8388
_umbracoContextFactory = umbracoContextFactory;
@@ -88,6 +93,8 @@ public UmbracoRequestMiddleware(
8893
_umbracoRequestPaths = umbracoRequestPaths;
8994
_backOfficeWebAssets = backOfficeWebAssets;
9095
_runtimeState = runtimeState;
96+
_variationContextAccessor = variationContextAccessor;
97+
_defaultCultureAccessor = defaultCultureAccessor;
9198
_smidgeOptions = smidgeOptions.Value;
9299
_profiler = profiler as WebProfiler; // Ignore if not a WebProfiler
93100
}
@@ -110,6 +117,7 @@ public async Task InvokeAsync(HttpContext context, RequestDelegate next)
110117

111118
EnsureContentCacheInitialized();
112119

120+
_variationContextAccessor.VariationContext ??= new VariationContext(_defaultCultureAccessor.DefaultCulture);
113121
UmbracoContextReference umbracoContextReference = _umbracoContextFactory.EnsureUmbracoContext();
114122

115123
Uri currentApplicationUrl = GetApplicationUrlFromCurrentRequest(context.Request);

0 commit comments

Comments
 (0)