Inject the IRazorViewEngine directory instead of using GetRequiredService
This commit is contained in:
parent
ab76f743f4
commit
90f0e29923
|
|
@ -15,24 +15,24 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Internal
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of <see cref="MvcRazorMvcViewOptionsSetup"/>.
|
/// Initializes a new instance of <see cref="MvcRazorMvcViewOptionsSetup"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="serviceProvider">The application's <see cref="IServiceProvider"/>.</param>
|
/// <param name="razorViewEngine">The <see cref="IRazorViewEngine"/>.</param>
|
||||||
public MvcRazorMvcViewOptionsSetup(IServiceProvider serviceProvider)
|
public MvcRazorMvcViewOptionsSetup(IRazorViewEngine razorViewEngine)
|
||||||
: base(options => ConfigureMvc(serviceProvider, options))
|
: base(options => ConfigureMvc(razorViewEngine, options))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Configures <paramref name="options"/> to use <see cref="RazorViewEngine"/>.
|
/// Configures <paramref name="options"/> to use <see cref="RazorViewEngine"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="serviceProvider">The application's <see cref="IServiceProvider"/>.</param>
|
/// <param name="razorViewEngine">The <see cref="IRazorViewEngine"/>.</param>
|
||||||
/// <param name="options">The <see cref="MvcViewOptions"/> to configure.</param>
|
/// <param name="options">The <see cref="MvcViewOptions"/> to configure.</param>
|
||||||
public static void ConfigureMvc(
|
public static void ConfigureMvc(
|
||||||
IServiceProvider serviceProvider,
|
IRazorViewEngine razorViewEngine,
|
||||||
MvcViewOptions options)
|
MvcViewOptions options)
|
||||||
{
|
{
|
||||||
if (serviceProvider == null)
|
if (razorViewEngine == null)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(serviceProvider));
|
throw new ArgumentNullException(nameof(razorViewEngine));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options == null)
|
if (options == null)
|
||||||
|
|
@ -40,7 +40,6 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Internal
|
||||||
throw new ArgumentNullException(nameof(options));
|
throw new ArgumentNullException(nameof(options));
|
||||||
}
|
}
|
||||||
|
|
||||||
var razorViewEngine = serviceProvider.GetRequiredService<IRazorViewEngine>();
|
|
||||||
options.ViewEngines.Add(razorViewEngine);
|
options.ViewEngines.Add(razorViewEngine);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue