-
Notifications
You must be signed in to change notification settings - Fork 448
Expand file tree
/
Copy pathFluentEmailServiceCollectionExtensions.cs
More file actions
34 lines (28 loc) · 1.14 KB
/
FluentEmailServiceCollectionExtensions.cs
File metadata and controls
34 lines (28 loc) · 1.14 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
using System;
using FluentEmail.Core;
using FluentEmail.Core.Interfaces;
using Microsoft.Extensions.DependencyInjection.Extensions;
namespace Microsoft.Extensions.DependencyInjection
{
public static class FluentEmailServiceCollectionExtensions
{
public static FluentEmailServicesBuilder AddFluentEmail(this IServiceCollection services, string defaultFromEmail, string defaultFromName = "")
{
if (services == null) throw new ArgumentNullException(nameof(services));
var builder = new FluentEmailServicesBuilder(services);
services.TryAdd(ServiceDescriptor.Transient<IFluentEmail>(x =>
new Email(x.GetService<ITemplateRenderer>(), x.GetService<ISender>(), defaultFromEmail, defaultFromName)
));
services.TryAddTransient<IFluentEmailFactory, FluentEmailFactory>();
return builder;
}
}
public class FluentEmailServicesBuilder
{
public IServiceCollection Services { get; private set; }
internal FluentEmailServicesBuilder(IServiceCollection services)
{
Services = services;
}
}
}