forked from lukencode/FluentEmail
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FluentEmailRazorBuilderExtensions.cs
53 lines (49 loc) · 2.11 KB
/
FluentEmailRazorBuilderExtensions.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
51
52
53
using System;
using FluentEmail.Core.Interfaces;
using FluentEmail.Razor;
using Microsoft.Extensions.DependencyInjection.Extensions;
using RazorLight.Razor;
namespace Microsoft.Extensions.DependencyInjection
{
public static class FluentEmailRazorBuilderExtensions
{
public static FluentEmailServicesBuilder AddRazorRenderer(this FluentEmailServicesBuilder builder)
{
builder.Services.TryAdd(ServiceDescriptor.Singleton<ITemplateRenderer, RazorRenderer>(_ => new RazorRenderer()));
return builder;
}
/// <summary>
/// Add razor renderer with project views and layouts
/// </summary>
/// <param name="builder"></param>
/// <param name="templateRootFolder"></param>
/// <returns></returns>
public static FluentEmailServicesBuilder AddRazorRenderer(this FluentEmailServicesBuilder builder, string templateRootFolder)
{
builder.Services.TryAdd(ServiceDescriptor.Singleton<ITemplateRenderer, RazorRenderer>(_ => new RazorRenderer(templateRootFolder)));
return builder;
}
/// <summary>
/// Add razor renderer with embedded views and layouts
/// </summary>
/// <param name="builder"></param>
/// <param name="embeddedResourceRootType"></param>
/// <returns></returns>
public static FluentEmailServicesBuilder AddRazorRenderer(this FluentEmailServicesBuilder builder, Type embeddedResourceRootType)
{
builder.Services.TryAdd(ServiceDescriptor.Singleton<ITemplateRenderer, RazorRenderer>(_ => new RazorRenderer( embeddedResourceRootType)));
return builder;
}
/// <summary>
/// Add razor renderer with a RazorLightProject to support views and layouts
/// </summary>
/// <param name="builder"></param>
/// <param name="razorLightProject"></param>
/// <returns></returns>
public static FluentEmailServicesBuilder AddRazorRenderer(this FluentEmailServicesBuilder builder, RazorLightProject razorLightProject)
{
builder.Services.TryAdd(ServiceDescriptor.Singleton<ITemplateRenderer, RazorRenderer>(_ => new RazorRenderer(razorLightProject)));
return builder;
}
}
}