Skip to content

Commit

Permalink
Replace email service project with NuGet package
Browse files Browse the repository at this point in the history
  • Loading branch information
dougwaldron committed Dec 5, 2024
1 parent 34a18a9 commit 6713fa7
Show file tree
Hide file tree
Showing 25 changed files with 88 additions and 297 deletions.
1 change: 1 addition & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<PackageVersion Include="Dapper" Version="2.1.35" />
<PackageVersion Include="FluentValidation.AspNetCore" Version="11.3.0" />
<PackageVersion Include="GaEpd.AppLibrary" Version="5.3.1" />
<PackageVersion Include="GaEpd.EmailService" Version="1.0.0" />
<PackageVersion Include="GaEpd.FileService" Version="3.1.1" />
<PackageVersion Include="HtmlSanitizer" Version="8.1.870" />
<PackageVersion Include="JetBrains.Annotations" Version="2024.3.0" />
Expand Down
2 changes: 1 addition & 1 deletion src/AppServices/AppServices.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<PackageReference Include="AutoMapper" />
<PackageReference Include="ClosedXML" />
<PackageReference Include="FluentValidation.AspNetCore" />
<PackageReference Include="GaEpd.EmailService" />
<PackageReference Include="GaEpd.FileService" />
<PackageReference Include="JetBrains.Annotations" />
<PackageReference Include="Microsoft.Identity.Web" />
Expand All @@ -22,7 +23,6 @@

<ItemGroup>
<ProjectReference Include="..\Domain\Domain.csproj" />
<ProjectReference Include="..\EmailService\EmailService.csproj" />
</ItemGroup>

</Project>
8 changes: 4 additions & 4 deletions src/AppServices/Notifications/NotificationService.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using GaEpd.EmailService;
using GaEpd.EmailService.Repository;
using GaEpd.EmailService.EmailLogRepository;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using MyApp.AppServices.ErrorLogging;
Expand Down Expand Up @@ -39,15 +39,15 @@ public async Task<NotificationResult> SendNotificationAsync(Template template, s
Message message;
try
{
message = Message.Create(subject, recipientEmail, settings.DefaultSender, textBody, htmlBody);
message = Message.Create(subject, recipientEmail, textBody, htmlBody);
}
catch (Exception e)
{
await errorLogger.LogErrorAsync(e, subject).ConfigureAwait(false);
return NotificationResult.FailureResult($"{FailurePrefix} An error occurred when generating the email.");
}

if (settings.SaveEmail) await repository.InsertAsync(EmailLog.Create(message), token).ConfigureAwait(false);
if (settings.EnableEmailLog) await repository.InsertAsync(message, token).ConfigureAwait(false);

if (settings is { EnableEmail: false, EnableEmailAuditing: false })
{
Expand All @@ -56,7 +56,7 @@ public async Task<NotificationResult> SendNotificationAsync(Template template, s

try
{
await emailService.SendEmailAsync(message, settings, token).ConfigureAwait(false);
_ = emailService.SendEmailAsync(message, token).ConfigureAwait(false);
}
catch (Exception e)
{
Expand Down
6 changes: 2 additions & 4 deletions src/AppServices/RegisterServices/AutoMapperProfiles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ namespace MyApp.AppServices.RegisterServices;

public static class AutoMapperProfiles
{
public static void AddAutoMapperProfiles(this IServiceCollection services)
{
// Add AutoMapper profiles
// Add AutoMapper profiles
public static IServiceCollection AddAutoMapperProfiles(this IServiceCollection services) =>
services.AddAutoMapper(expression => expression.AddProfile<AutoMapperProfile>());
}
}
7 changes: 4 additions & 3 deletions src/AppServices/RegisterServices/RegisterAppServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace MyApp.AppServices.RegisterServices;

public static class RegisterAppServices
{
public static void AddAppServices(this IServiceCollection services)
public static IServiceCollection AddAppServices(this IServiceCollection services)
{
// Work Entries
services.AddScoped<IWorkEntryManager, WorkEntryManager>();
Expand All @@ -27,8 +27,7 @@ public static void AddAppServices(this IServiceCollection services)
services.AddScoped<IEntryTypeManager, EntryTypeManager>();
services.AddScoped<IEntryTypeService, EntryTypeService>();

// Email
services.AddTransient<IEmailService, EmailService>();
// Notifications
services.AddScoped<INotificationService, NotificationService>();

// Offices
Expand All @@ -37,5 +36,7 @@ public static void AddAppServices(this IServiceCollection services)

// Data Export
services.AddScoped<ISearchResultsExportService, SearchResultsExportService>();

return services;
}
}
2 changes: 1 addition & 1 deletion src/AppServices/RegisterServices/Validators.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ namespace MyApp.AppServices.RegisterServices;
public static class Validators
{
// Add all validators
public static void AddValidators(this IServiceCollection services) =>
public static IServiceCollection AddValidators(this IServiceCollection services) =>
services.AddValidatorsFromAssemblyContaining(typeof(Validators));
}
2 changes: 1 addition & 1 deletion src/EfRepository/DbContext/AppDbContext.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using GaEpd.EmailService.Repository;
using GaEpd.EmailService.EmailLogRepository;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using MyApp.Domain.Entities.EntryActions;
Expand Down
13 changes: 10 additions & 3 deletions src/EfRepository/Repositories/EmailLogRepository.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
using GaEpd.EmailService.Repository;
using GaEpd.EmailService;
using GaEpd.EmailService.EmailLogRepository;
using Microsoft.Extensions.Configuration;
using MyApp.EfRepository.DbContext;

namespace MyApp.EfRepository.Repositories;

public sealed class EmailLogRepository(AppDbContext dbContext) : IEmailLogRepository
public sealed class EmailLogRepository(AppDbContext dbContext, IConfiguration configuration) : IEmailLogRepository
{
public async Task InsertAsync(EmailLog emailLog, CancellationToken token = default)
public async Task InsertAsync(Message message, CancellationToken token = default)
{
var settings = new EmailServiceSettings();
configuration.GetSection(nameof(EmailServiceSettings)).Bind(settings);
if (!settings.EnableEmailLog) return;

var emailLog = EmailLog.Create(message);
await dbContext.EmailLogs.AddAsync(emailLog, token).ConfigureAwait(false);
await dbContext.SaveChangesAsync(token).ConfigureAwait(false);
}
Expand Down
65 changes: 0 additions & 65 deletions src/EmailService/EmailService.cs

This file was deleted.

16 changes: 0 additions & 16 deletions src/EmailService/EmailService.csproj

This file was deleted.

2 changes: 0 additions & 2 deletions src/EmailService/EmailService.csproj.DotSettings

This file was deleted.

13 changes: 0 additions & 13 deletions src/EmailService/EmailServiceSettings.cs

This file was deleted.

6 changes: 0 additions & 6 deletions src/EmailService/IEmailService.cs

This file was deleted.

44 changes: 0 additions & 44 deletions src/EmailService/Message.cs

This file was deleted.

3 changes: 0 additions & 3 deletions src/EmailService/Properties/AssemblyInfo.cs

This file was deleted.

42 changes: 0 additions & 42 deletions src/EmailService/Repository/EmailLog.cs

This file was deleted.

12 changes: 0 additions & 12 deletions src/EmailService/Repository/IEmailLogRepository.cs

This file was deleted.

21 changes: 0 additions & 21 deletions src/EmailService/Utilities/StringExtensions.cs

This file was deleted.

5 changes: 3 additions & 2 deletions src/LocalRepository/Repositories/LocalEmailLogRepository.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
using GaEpd.EmailService.Repository;
using GaEpd.EmailService;
using GaEpd.EmailService.EmailLogRepository;

namespace MyApp.LocalRepository.Repositories;

public sealed class LocalEmailLogRepository : IEmailLogRepository
{
public Task InsertAsync(EmailLog emailLog, CancellationToken token = default) => Task.CompletedTask;
public Task InsertAsync(Message message, CancellationToken token = default) => Task.CompletedTask;

public void Dispose()
{
Expand Down
Loading

0 comments on commit 6713fa7

Please sign in to comment.