-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMarkdownMvcBuilderExtensions.cs
48 lines (41 loc) · 1.7 KB
/
MarkdownMvcBuilderExtensions.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
using My.AspNetCore.Mvc.Markdown;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using System;
namespace Microsoft.Extensions.DependencyInjection
{
public static class MarkdownMvcBuilderExtensions
{
public static IMvcBuilder AddMarkdownViewEngine(this IMvcBuilder builder)
{
if (builder == null)
{
throw new ArgumentNullException(nameof(builder));
}
builder.Services.AddOptions();
builder.Services.AddTransient<IConfigureOptions<MarkdownViewEngineOptions>, MarkdownViewEngineOptionsSetup>();
builder.Services.AddTransient<IConfigureOptions<MvcViewOptions>, MarkdownMvcViewOptionsSetup>();
builder.Services.AddSingleton<IMarkdownViewEngine, MarkdownViewEngine>();
return builder;
}
public static IMvcBuilder AddMarkdownViewEngine(
this IMvcBuilder builder,
Action<MarkdownViewEngineOptions> setupAction)
{
if (builder == null)
{
throw new ArgumentNullException(nameof(builder));
}
if (setupAction == null)
{
throw new ArgumentNullException(nameof(setupAction));
}
builder.Services.AddOptions();
builder.Services.AddTransient<IConfigureOptions<MarkdownViewEngineOptions>, MarkdownViewEngineOptionsSetup>();
builder.Services.Configure(setupAction);
builder.Services.AddTransient<IConfigureOptions<MvcViewOptions>, MarkdownMvcViewOptionsSetup>();
builder.Services.AddSingleton<IMarkdownViewEngine, MarkdownViewEngine>();
return builder;
}
}
}