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