-
Notifications
You must be signed in to change notification settings - Fork 9.8k
/
RazorRuntimeCompilationMvcBuilderExtensions.cs
50 lines (44 loc) · 1.99 KB
/
RazorRuntimeCompilationMvcBuilderExtensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation;
namespace Microsoft.Extensions.DependencyInjection
{
public static class RazorRuntimeCompilationMvcBuilderExtensions
{
/// <summary>
/// Configures <see cref="IMvcBuilder" /> to support runtime compilation of Razor views and Razor Pages.
/// </summary>
/// <param name="builder">The <see cref="IMvcBuilder" />.</param>
/// <returns>The <see cref="IMvcBuilder"/>.</returns>
public static IMvcBuilder AddRazorRuntimeCompilation(this IMvcBuilder builder)
{
if (builder == null)
{
throw new ArgumentNullException(nameof(builder));
}
RazorRuntimeCompilationMvcCoreBuilderExtensions.AddServices(builder.Services);
return builder;
}
/// <summary>
/// Configures <see cref="IMvcBuilder" /> to support runtime compilation of Razor views and Razor Pages.
/// </summary>
/// <param name="builder">The <see cref="IMvcBuilder" />.</param>
/// <param name="setupAction">An action to configure the <see cref="MvcRazorRuntimeCompilationOptions"/>.</param>
/// <returns>The <see cref="IMvcBuilder"/>.</returns>
public static IMvcBuilder AddRazorRuntimeCompilation(this IMvcBuilder builder, Action<MvcRazorRuntimeCompilationOptions> setupAction)
{
if (builder == null)
{
throw new ArgumentNullException(nameof(builder));
}
if (setupAction == null)
{
throw new ArgumentNullException(nameof(setupAction));
}
RazorRuntimeCompilationMvcCoreBuilderExtensions.AddServices(builder.Services);
builder.Services.Configure(setupAction);
return builder;
}
}
}