Skip to content

Commit

Permalink
Fix Notify registrations for Worker (#1009)
Browse files Browse the repository at this point in the history
  • Loading branch information
gunndabad authored Dec 18, 2023
1 parent e2087f7 commit 94fa550
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 36 deletions.
2 changes: 0 additions & 2 deletions TeachingRecordSystem/src/TeachingRecordSystem.Api/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
using TeachingRecordSystem.Core.Infrastructure;
using TeachingRecordSystem.Core.Services.Certificates;
using TeachingRecordSystem.Core.Services.GetAnIdentityApi;
using TeachingRecordSystem.Core.Services.Notify;
using TeachingRecordSystem.Core.Services.TrnGenerationApi;
using TeachingRecordSystem.ServiceDefaults;

Expand Down Expand Up @@ -188,7 +187,6 @@ public static void Main(string[] args)
services.AddIdentityApi(configuration, env);
services.AddAccessYourTeachingQualificationsOptions(configuration, env);
services.AddCertificateGeneration();
services.AddEmail(env, configuration);
services.AddCrmQueries();

if (!env.IsUnitTests())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

namespace TeachingRecordSystem.Core.Services.Notify;

public static class HostApplicationBuilderExtensions
{
public static IHostApplicationBuilder AddEmail(this IHostApplicationBuilder builder)
{
if (builder.Environment.IsProduction())
{
builder.Services.AddOptions<NotifyOptions>()
.Bind(builder.Configuration.GetSection("Notify"))
.ValidateDataAnnotations()
.ValidateOnStart();

builder.Services.AddSingleton<INotificationSender, NotificationSender>();
}
else
{
builder.Services.AddSingleton<INotificationSender, NoopNotificationSender>();
}

return builder;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using TeachingRecordSystem.Core.Infrastructure.Configuration;
using TeachingRecordSystem.Core.Jobs;
using TeachingRecordSystem.Core.Services.DqtReporting;
using TeachingRecordSystem.Core.Services.Notify;
using TeachingRecordSystem.Core.Services.TrnGenerationApi;
using TeachingRecordSystem.Core.Services.TrsDataSync;
using TeachingRecordSystem.Hosting;
Expand All @@ -33,7 +34,8 @@
.AddTrsSyncService()
.AddHangfire()
.AddBackgroundJobs()
.AddBackgroundWorkScheduler();
.AddBackgroundWorkScheduler()
.AddEmail();

var crmServiceClient = new ServiceClient(builder.Configuration.GetRequiredValue("ConnectionStrings:Crm"))
{
Expand Down

0 comments on commit 94fa550

Please sign in to comment.