-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using Aviant.Application.Email; | ||
using Aviant.Infrastructure.Email; | ||
|
||
namespace CleanDDDArchitecture.Hosts.RestApi.Presentation.ServiceExtensions; | ||
|
||
/// <summary> | ||
/// Email service extension | ||
/// </summary> | ||
public static class Email | ||
{ | ||
/// <summary> | ||
/// Add email service | ||
/// </summary> | ||
/// <param name="services"></param> | ||
/// <param name="configuration"></param> | ||
/// <returns></returns> | ||
public static IServiceCollection AddEmailService( | ||
this IServiceCollection services, | ||
IConfiguration configuration) | ||
{ | ||
// Get the configuration properties | ||
var smtpHost = configuration["EmailSettings:SmtpHost"]; | ||
var smtpPort = int.Parse(configuration["EmailSettings:SmtpPort"]); | ||
var enableSsl = bool.Parse(configuration["EmailSettings:EnableSsl"]); | ||
var smtpUsername = configuration["EmailSettings:SmtpUsername"]; | ||
var smtpPassword = configuration["EmailSettings:SmtpPassword"]; | ||
var fromName = configuration["EmailSettings:FromName"]; | ||
var fromEmail = configuration["EmailSettings:FromEmail"]; | ||
|
||
services.AddSingleton<ISmtpClientFactory, SmtpClientFactory>( | ||
provider => new SmtpClientFactory( | ||
smtpHost, | ||
smtpPort, | ||
enableSsl, | ||
smtpUsername, | ||
smtpPassword)); | ||
|
||
services.AddTransient<IEmailService, EmailService>( | ||
provider => | ||
{ | ||
var smtpClientFactory = provider.GetRequiredService<ISmtpClientFactory>(); | ||
|
||
return new EmailService(smtpClientFactory, fromName, fromEmail); | ||
}); | ||
|
||
return services; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
--- | ||
EmailSettings: | ||
FromName: "Clean DDD Architecture" | ||
FromEmail: "[email protected]" | ||
|
||
Serilog: | ||
Using: | ||
|