Skip to content

Commit

Permalink
Add Email Service
Browse files Browse the repository at this point in the history
  • Loading branch information
panosru committed Feb 19, 2024
1 parent 398042b commit 2017e17
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 0 deletions.
1 change: 1 addition & 0 deletions Domains/Shared/Application/Application.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

<ItemGroup>
<ProjectReference Include="..\..\..\Library\Aviant\src\DDD\Application\Application.csproj" />
<ProjectReference Include="..\..\..\Library\Aviant\src\Email\Application\Application.csproj" />
<ProjectReference Include="..\..\..\Library\Aviant\src\Kernel\Application\Application.csproj" />
<ProjectReference Include="..\Core\Core.csproj" />
</ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions Domains/Shared/Infrastructure/Infrastructure.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

<ItemGroup>
<ProjectReference Include="..\..\..\Library\Aviant\src\DDD\Infrastructure\Infrastructure.csproj" />
<ProjectReference Include="..\..\..\Library\Aviant\src\Email\Infrastructure\Infrastructure.csproj" />
<ProjectReference Include="..\..\..\Library\Aviant\src\Kernel\Infrastructure\Infrastructure.csproj" />
<ProjectReference Include="..\Application\Application.csproj" />
</ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions Hosts/RestApi/Presentation/ServiceConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public static void ConfigureServices(
services.AddSingleton(configuration);
DependencyInjectionRegistry.CurrentEnvironment = environment;

services.AddEmailService(configuration);
services.AddAutoMapperServices();
services.AddValidatorServices();
services.AddDataProtectionServices();
Expand Down
48 changes: 48 additions & 0 deletions Hosts/RestApi/Presentation/ServiceExtensions/Email.cs
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;
}
}
3 changes: 3 additions & 0 deletions Hosts/RestApi/Presentation/appsettings.Development.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
---
EmailSettings:
FromName: "Clean DDD Architecture"
FromEmail: "[email protected]"

Serilog:
Using:
Expand Down

0 comments on commit 2017e17

Please sign in to comment.