[Fixes #4224] Remove use of service locator on ViewExecutor
This commit is contained in:
parent
6a6d2e0d9f
commit
4b5df98bc3
|
|
@ -8,6 +8,7 @@ using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Mvc.Controllers;
|
using Microsoft.AspNetCore.Mvc.Controllers;
|
||||||
using Microsoft.AspNetCore.Mvc.Internal;
|
using Microsoft.AspNetCore.Mvc.Internal;
|
||||||
|
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
||||||
using Microsoft.AspNetCore.Mvc.ViewEngines;
|
using Microsoft.AspNetCore.Mvc.ViewEngines;
|
||||||
using Microsoft.AspNetCore.Mvc.ViewFeatures.Internal;
|
using Microsoft.AspNetCore.Mvc.ViewFeatures.Internal;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
@ -31,14 +32,16 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal
|
||||||
/// <param name="tempDataFactory">The <see cref="ITempDataDictionaryFactory"/>.</param>
|
/// <param name="tempDataFactory">The <see cref="ITempDataDictionaryFactory"/>.</param>
|
||||||
/// <param name="diagnosticSource">The <see cref="DiagnosticSource"/>.</param>
|
/// <param name="diagnosticSource">The <see cref="DiagnosticSource"/>.</param>
|
||||||
/// <param name="loggerFactory">The <see cref="ILoggerFactory"/>.</param>
|
/// <param name="loggerFactory">The <see cref="ILoggerFactory"/>.</param>
|
||||||
|
/// <param name="modelMetadataProvider">The <see cref="IModelMetadataProvider"/>.</param>
|
||||||
public PartialViewResultExecutor(
|
public PartialViewResultExecutor(
|
||||||
IOptions<MvcViewOptions> viewOptions,
|
IOptions<MvcViewOptions> viewOptions,
|
||||||
IHttpResponseStreamWriterFactory writerFactory,
|
IHttpResponseStreamWriterFactory writerFactory,
|
||||||
ICompositeViewEngine viewEngine,
|
ICompositeViewEngine viewEngine,
|
||||||
ITempDataDictionaryFactory tempDataFactory,
|
ITempDataDictionaryFactory tempDataFactory,
|
||||||
DiagnosticSource diagnosticSource,
|
DiagnosticSource diagnosticSource,
|
||||||
ILoggerFactory loggerFactory)
|
ILoggerFactory loggerFactory,
|
||||||
: base(viewOptions, writerFactory, viewEngine, tempDataFactory, diagnosticSource)
|
IModelMetadataProvider modelMetadataProvider)
|
||||||
|
: base(viewOptions, writerFactory, viewEngine, tempDataFactory, diagnosticSource, modelMetadataProvider)
|
||||||
{
|
{
|
||||||
if (loggerFactory == null)
|
if (loggerFactory == null)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Mvc.Controllers;
|
using Microsoft.AspNetCore.Mvc.Controllers;
|
||||||
using Microsoft.AspNetCore.Mvc.Internal;
|
using Microsoft.AspNetCore.Mvc.Internal;
|
||||||
|
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
||||||
using Microsoft.AspNetCore.Mvc.ViewEngines;
|
using Microsoft.AspNetCore.Mvc.ViewEngines;
|
||||||
using Microsoft.AspNetCore.Mvc.ViewFeatures.Internal;
|
using Microsoft.AspNetCore.Mvc.ViewFeatures.Internal;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
@ -31,14 +32,16 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal
|
||||||
/// <param name="tempDataFactory">The <see cref="ITempDataDictionaryFactory"/>.</param>
|
/// <param name="tempDataFactory">The <see cref="ITempDataDictionaryFactory"/>.</param>
|
||||||
/// <param name="diagnosticSource">The <see cref="DiagnosticSource"/>.</param>
|
/// <param name="diagnosticSource">The <see cref="DiagnosticSource"/>.</param>
|
||||||
/// <param name="loggerFactory">The <see cref="ILoggerFactory"/>.</param>
|
/// <param name="loggerFactory">The <see cref="ILoggerFactory"/>.</param>
|
||||||
|
/// <param name="modelMetadataProvider">The <see cref="IModelMetadataProvider"/>.</param>
|
||||||
public ViewResultExecutor(
|
public ViewResultExecutor(
|
||||||
IOptions<MvcViewOptions> viewOptions,
|
IOptions<MvcViewOptions> viewOptions,
|
||||||
IHttpResponseStreamWriterFactory writerFactory,
|
IHttpResponseStreamWriterFactory writerFactory,
|
||||||
ICompositeViewEngine viewEngine,
|
ICompositeViewEngine viewEngine,
|
||||||
ITempDataDictionaryFactory tempDataFactory,
|
ITempDataDictionaryFactory tempDataFactory,
|
||||||
DiagnosticSource diagnosticSource,
|
DiagnosticSource diagnosticSource,
|
||||||
ILoggerFactory loggerFactory)
|
ILoggerFactory loggerFactory,
|
||||||
: base(viewOptions, writerFactory, viewEngine, tempDataFactory, diagnosticSource)
|
IModelMetadataProvider modelMetadataProvider)
|
||||||
|
: base(viewOptions, writerFactory, viewEngine, tempDataFactory, diagnosticSource, modelMetadataProvider)
|
||||||
{
|
{
|
||||||
if (loggerFactory == null)
|
if (loggerFactory == null)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,8 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static readonly string DefaultContentType = "text/html; charset=utf-8";
|
public static readonly string DefaultContentType = "text/html; charset=utf-8";
|
||||||
|
|
||||||
|
private readonly IModelMetadataProvider _modelMetadataProvider;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a new <see cref="ViewExecutor"/>.
|
/// Creates a new <see cref="ViewExecutor"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -33,12 +35,14 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures
|
||||||
/// <param name="viewEngine">The <see cref="ICompositeViewEngine"/>.</param>
|
/// <param name="viewEngine">The <see cref="ICompositeViewEngine"/>.</param>
|
||||||
/// <param name="tempDataFactory">The <see cref="ITempDataDictionaryFactory"/>.</param>
|
/// <param name="tempDataFactory">The <see cref="ITempDataDictionaryFactory"/>.</param>
|
||||||
/// <param name="diagnosticSource">The <see cref="DiagnosticSource"/>.</param>
|
/// <param name="diagnosticSource">The <see cref="DiagnosticSource"/>.</param>
|
||||||
|
/// <param name="modelMetadataProvider">The <see cref="IModelMetadataProvider" />.</param>
|
||||||
public ViewExecutor(
|
public ViewExecutor(
|
||||||
IOptions<MvcViewOptions> viewOptions,
|
IOptions<MvcViewOptions> viewOptions,
|
||||||
IHttpResponseStreamWriterFactory writerFactory,
|
IHttpResponseStreamWriterFactory writerFactory,
|
||||||
ICompositeViewEngine viewEngine,
|
ICompositeViewEngine viewEngine,
|
||||||
ITempDataDictionaryFactory tempDataFactory,
|
ITempDataDictionaryFactory tempDataFactory,
|
||||||
DiagnosticSource diagnosticSource)
|
DiagnosticSource diagnosticSource,
|
||||||
|
IModelMetadataProvider modelMetadataProvider)
|
||||||
{
|
{
|
||||||
if (viewOptions == null)
|
if (viewOptions == null)
|
||||||
{
|
{
|
||||||
|
|
@ -65,11 +69,17 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures
|
||||||
throw new ArgumentNullException(nameof(diagnosticSource));
|
throw new ArgumentNullException(nameof(diagnosticSource));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (modelMetadataProvider == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(modelMetadataProvider));
|
||||||
|
}
|
||||||
|
|
||||||
ViewOptions = viewOptions.Value;
|
ViewOptions = viewOptions.Value;
|
||||||
WriterFactory = writerFactory;
|
WriterFactory = writerFactory;
|
||||||
ViewEngine = viewEngine;
|
ViewEngine = viewEngine;
|
||||||
TempDataFactory = tempDataFactory;
|
TempDataFactory = tempDataFactory;
|
||||||
DiagnosticSource = diagnosticSource;
|
DiagnosticSource = diagnosticSource;
|
||||||
|
_modelMetadataProvider = modelMetadataProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -132,9 +142,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures
|
||||||
|
|
||||||
if (viewData == null)
|
if (viewData == null)
|
||||||
{
|
{
|
||||||
var services = actionContext.HttpContext.RequestServices;
|
viewData = new ViewDataDictionary(_modelMetadataProvider, actionContext.ModelState);
|
||||||
var metadataProvider = services.GetRequiredService<IModelMetadataProvider>();
|
|
||||||
viewData = new ViewDataDictionary(metadataProvider, actionContext.ModelState);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tempData == null)
|
if (tempData == null)
|
||||||
|
|
|
||||||
|
|
@ -342,7 +342,8 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal
|
||||||
new CompositeViewEngine(options),
|
new CompositeViewEngine(options),
|
||||||
new TempDataDictionaryFactory(new SessionStateTempDataProvider()),
|
new TempDataDictionaryFactory(new SessionStateTempDataProvider()),
|
||||||
diagnosticSource,
|
diagnosticSource,
|
||||||
NullLoggerFactory.Instance);
|
NullLoggerFactory.Instance,
|
||||||
|
new EmptyModelMetadataProvider());
|
||||||
|
|
||||||
return viewExecutor;
|
return viewExecutor;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -199,7 +199,8 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal
|
||||||
new CompositeViewEngine(options),
|
new CompositeViewEngine(options),
|
||||||
new TempDataDictionaryFactory(new SessionStateTempDataProvider()),
|
new TempDataDictionaryFactory(new SessionStateTempDataProvider()),
|
||||||
new DiagnosticListener("Microsoft.AspNetCore"),
|
new DiagnosticListener("Microsoft.AspNetCore"),
|
||||||
NullLoggerFactory.Instance);
|
NullLoggerFactory.Instance,
|
||||||
|
new EmptyModelMetadataProvider());
|
||||||
|
|
||||||
var services = new ServiceCollection();
|
var services = new ServiceCollection();
|
||||||
services.AddSingleton(viewExecutor);
|
services.AddSingleton(viewExecutor);
|
||||||
|
|
|
||||||
|
|
@ -332,7 +332,8 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal
|
||||||
new CompositeViewEngine(options),
|
new CompositeViewEngine(options),
|
||||||
new TempDataDictionaryFactory(new SessionStateTempDataProvider()),
|
new TempDataDictionaryFactory(new SessionStateTempDataProvider()),
|
||||||
diagnosticSource,
|
diagnosticSource,
|
||||||
NullLoggerFactory.Instance);
|
NullLoggerFactory.Instance,
|
||||||
|
new EmptyModelMetadataProvider());
|
||||||
|
|
||||||
return viewExecutor;
|
return viewExecutor;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -364,7 +364,8 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures
|
||||||
new TestHttpResponseStreamWriterFactory(),
|
new TestHttpResponseStreamWriterFactory(),
|
||||||
new Mock<ICompositeViewEngine>(MockBehavior.Strict).Object,
|
new Mock<ICompositeViewEngine>(MockBehavior.Strict).Object,
|
||||||
new TempDataDictionaryFactory(new SessionStateTempDataProvider()),
|
new TempDataDictionaryFactory(new SessionStateTempDataProvider()),
|
||||||
diagnosticSource);
|
diagnosticSource,
|
||||||
|
new EmptyModelMetadataProvider());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -227,7 +227,8 @@ namespace Microsoft.AspNetCore.Mvc
|
||||||
new CompositeViewEngine(options),
|
new CompositeViewEngine(options),
|
||||||
new TempDataDictionaryFactory(new SessionStateTempDataProvider()),
|
new TempDataDictionaryFactory(new SessionStateTempDataProvider()),
|
||||||
new DiagnosticListener("Microsoft.AspNetCore"),
|
new DiagnosticListener("Microsoft.AspNetCore"),
|
||||||
NullLoggerFactory.Instance);
|
NullLoggerFactory.Instance,
|
||||||
|
new EmptyModelMetadataProvider());
|
||||||
|
|
||||||
var services = new ServiceCollection();
|
var services = new ServiceCollection();
|
||||||
services.AddSingleton(viewExecutor);
|
services.AddSingleton(viewExecutor);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue