forked from lukencode/FluentEmail
-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathFluentEmailFluidBuilderExtensions.cs
More file actions
74 lines (66 loc) · 2.77 KB
/
Copy pathFluentEmailFluidBuilderExtensions.cs
File metadata and controls
74 lines (66 loc) · 2.77 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
using System;
using System.Reflection;
using FluentEmail.Core;
using FluentEmail.Core.Interfaces;
using FluentEmail.Liquid;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.FileProviders;
// ReSharper disable once CheckNamespace
namespace Microsoft.Extensions.DependencyInjection
{
public static class FluentEmailFluidBuilderExtensions
{
public static FluentEmailServicesBuilder AddLiquidRenderer(
this FluentEmailServicesBuilder builder,
Action<LiquidRendererOptions>? configure = null)
{
builder.Services.AddOptions<LiquidRendererOptions>();
if (configure != null)
{
builder.Services.Configure(configure);
}
builder.Services.TryAddSingleton<ITemplateRenderer, LiquidRenderer>();
return builder;
}
public static FluentEmailServicesBuilder AddLiquidRendererWithEmbedded(
this FluentEmailServicesBuilder builder,
Action<LiquidRendererOptions>? configure = null)
{
var assembly = Assembly.GetCallingAssembly();
var name = assembly.GetName().Name;
return AddLiquidRendererWithEmbedded(builder, assembly, $"{name}.EmailTemplates", configure);
}
public static FluentEmailServicesBuilder AddLiquidRendererWithEmbedded(
this FluentEmailServicesBuilder builder,
Assembly assembly,
Action<LiquidRendererOptions>? configure = null)
{
var name = assembly.GetName().Name;
return AddLiquidRendererWithEmbedded(builder, assembly, $"{name}.EmailTemplates", configure);
}
public static FluentEmailServicesBuilder AddLiquidRendererWithEmbedded(
this FluentEmailServicesBuilder builder,
string rootPath,
Action<LiquidRendererOptions>? configure = null)
{
var assembly = Assembly.GetCallingAssembly();
var name = assembly.GetName().Name;
if (!string.IsNullOrEmpty(rootPath)) name += ".";
return AddLiquidRendererWithEmbedded(builder, assembly, $"{name}{rootPath}", configure);
}
public static FluentEmailServicesBuilder AddLiquidRendererWithEmbedded(
this FluentEmailServicesBuilder builder,
Assembly assembly,
string rootNamespace,
Action<LiquidRendererOptions>? configure = null)
{
builder.AddLiquidRenderer(options =>
{
options.FileProvider = new EmbeddedFileProvider(assembly, rootNamespace);
configure?.Invoke(options);
});
EmbeddedTemplates.Configure(assembly, rootNamespace);
return builder;
}
}
}