Simplifies how view locations are determined

AB#9720
This commit is contained in:
Shannon
2021-01-04 15:43:30 +11:00
parent a6f281789b
commit a126977a4e
10 changed files with 120 additions and 228 deletions

View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNetCore.Mvc;
@@ -8,15 +8,20 @@ using Umbraco.Core.Logging;
namespace Umbraco.Web.Website.ViewEngines
{
/// <summary>
/// Wraps all view engines with a <see cref="ProfilingViewEngine"/>
/// </summary>
public class ProfilingViewEngineWrapperMvcViewOptionsSetup : IConfigureOptions<MvcViewOptions>
{
private readonly IProfiler _profiler;
public ProfilingViewEngineWrapperMvcViewOptionsSetup(IProfiler profiler)
{
_profiler = profiler ?? throw new ArgumentNullException(nameof(profiler));
}
/// <summary>
/// Initializes a new instance of the <see cref="ProfilingViewEngineWrapperMvcViewOptionsSetup"/> class.
/// </summary>
/// <param name="profiler">The <see cref="IProfiler"/></param>
public ProfilingViewEngineWrapperMvcViewOptionsSetup(IProfiler profiler) => _profiler = profiler ?? throw new ArgumentNullException(nameof(profiler));
/// <inheritdoc/>
public void Configure(MvcViewOptions options)
{
if (options == null)
@@ -29,13 +34,16 @@ namespace Umbraco.Web.Website.ViewEngines
private void WrapViewEngines(IList<IViewEngine> viewEngines)
{
if (viewEngines == null || viewEngines.Count == 0) return;
if (viewEngines == null || viewEngines.Count == 0)
{
return;
}
var originalEngines = viewEngines.ToList();
viewEngines.Clear();
foreach (var engine in originalEngines)
foreach (IViewEngine engine in originalEngines)
{
var wrappedEngine = engine is ProfilingViewEngine ? engine : new ProfilingViewEngine(engine, _profiler);
IViewEngine wrappedEngine = engine is ProfilingViewEngine ? engine : new ProfilingViewEngine(engine, _profiler);
viewEngines.Add(wrappedEngine);
}
}