Skip to content
This repository has been archived by the owner on Dec 14, 2018. It is now read-only.

Commit

Permalink
Inject the IRazorViewEngine directory instead of using GetRequiredSer…
Browse files Browse the repository at this point in the history
…vice
  • Loading branch information
pranavkm committed May 24, 2016
1 parent ab76f74 commit 90f0e29
Showing 1 changed file with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,31 @@ public class MvcRazorMvcViewOptionsSetup : ConfigureOptions<MvcViewOptions>
/// <summary>
/// Initializes a new instance of <see cref="MvcRazorMvcViewOptionsSetup"/>.
/// </summary>
/// <param name="serviceProvider">The application's <see cref="IServiceProvider"/>.</param>
public MvcRazorMvcViewOptionsSetup(IServiceProvider serviceProvider)
: base(options => ConfigureMvc(serviceProvider, options))
/// <param name="razorViewEngine">The <see cref="IRazorViewEngine"/>.</param>
public MvcRazorMvcViewOptionsSetup(IRazorViewEngine razorViewEngine)
: base(options => ConfigureMvc(razorViewEngine, options))
{
}

/// <summary>
/// Configures <paramref name="options"/> to use <see cref="RazorViewEngine"/>.
/// </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>
public static void ConfigureMvc(
IServiceProvider serviceProvider,
IRazorViewEngine razorViewEngine,
MvcViewOptions options)
{
if (serviceProvider == null)
if (razorViewEngine == null)
{
throw new ArgumentNullException(nameof(serviceProvider));
throw new ArgumentNullException(nameof(razorViewEngine));
}

if (options == null)
{
throw new ArgumentNullException(nameof(options));
}

var razorViewEngine = serviceProvider.GetRequiredService<IRazorViewEngine>();
options.ViewEngines.Add(razorViewEngine);
}
}
Expand Down

0 comments on commit 90f0e29

Please sign in to comment.