Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
namespace ServiceControl.Persistence.EFCore.Implementation;

public class NotificationsDataStore : INotificationsDataStore
using DbContexts;
using Microsoft.Extensions.DependencyInjection;

public class NotificationsDataStore(IServiceProvider serviceProvider) : INotificationsDataStore
{
public Task<INotificationsManager> CreateNotificationsManager() =>
throw new NotImplementedException();
public Task<INotificationsManager> CreateNotificationsManager()
{
var scope = serviceProvider.CreateAsyncScope();
ServiceControlDbContext serviceControlDbContext = scope.ServiceProvider.GetRequiredService<ServiceControlDbContext>();
return Task.FromResult<INotificationsManager>(new NotificationsManager(scope, serviceControlDbContext));
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,35 @@
namespace ServiceControl.Persistence.EFCore.Implementation;

using ServiceControl.Notifications;
using DbContexts;
using Infrastructure;
using Notifications;

public class NotificationsManager : INotificationsManager
public class NotificationsManager(IAsyncDisposable scope, ServiceControlDbContext dbContext) : INotificationsManager
{
public Task<NotificationsSettings> LoadSettings() =>
throw new NotImplementedException();
NotificationsSettings? _settings;

public Task SaveChanges() =>
throw new NotImplementedException();
public Task SaveChanges()
{
if (_settings == null)
{
return Task.CompletedTask;
}

public ValueTask DisposeAsync() => default;
}
return dbContext.StoreSetting(SettingKeys.NotificationEmails, _settings.Email, CancellationToken.None);
}

public async Task<NotificationsSettings> LoadSettings()
{
var settings = await dbContext.GetSetting<EmailNotifications>(SettingKeys.NotificationEmails, CancellationToken.None);
_settings = new NotificationsSettings() { Email = settings ?? new EmailNotifications() };
return _settings;
}

public async ValueTask DisposeAsync()
{
await dbContext.DisposeAsync();
await scope.DisposeAsync();

GC.SuppressFinalize(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ static class SettingKeys
public const string AuditServiceMetadata = "AuditServiceMetadata";
public const string ReportMasks = "ReportMasks";
public const string LicensedEndpointDetails = "LicensedEndpointDetails";
public const string NotificationEmails = "NotificationEmails";
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
<Compile Remove="..\ServiceControl.Persistence.Tests\Recoverability\EditMessageTests.cs" />
<Compile Remove="..\ServiceControl.Persistence.Tests\Recoverability\RetryConfirmationProcessorTests.cs" />
<Compile Remove="..\ServiceControl.Persistence.Tests\RetryStateTests.cs" />
<Compile Remove="..\ServiceControl.Persistence.Tests\NotificationsDataStoreTests.cs" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
<Compile Remove="..\ServiceControl.Persistence.Tests\Recoverability\EditMessageTests.cs" />
<Compile Remove="..\ServiceControl.Persistence.Tests\Recoverability\RetryConfirmationProcessorTests.cs" />
<Compile Remove="..\ServiceControl.Persistence.Tests\RetryStateTests.cs" />
<Compile Remove="..\ServiceControl.Persistence.Tests\NotificationsDataStoreTests.cs" />
</ItemGroup>

</Project>