mirror of
https://github.com/babalae/better-genshin-impact
synced 2025-01-09 04:19:47 +08:00
Register NotificationService as HostedService so it instantiates early
This commit is contained in:
parent
8c025feaba
commit
4f9424ff3d
@ -95,6 +95,7 @@ public partial class App : Application
|
||||
// My Services
|
||||
services.AddSingleton<TaskTriggerDispatcher>();
|
||||
services.AddSingleton<NotificationService>();
|
||||
services.AddHostedService<NotificationService>(sp => sp.GetRequiredService<NotificationService>());
|
||||
services.AddSingleton<NotifierManager>();
|
||||
|
||||
// Configuration
|
||||
|
@ -9,10 +9,12 @@ using BetterGenshinImpact.Service.Notifier;
|
||||
using BetterGenshinImpact.Service.Notifier.Exception;
|
||||
using BetterGenshinImpact.Service.Notifier.Interface;
|
||||
using System.Text.Json;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using System.Threading;
|
||||
|
||||
namespace BetterGenshinImpact.Service.Notification;
|
||||
|
||||
public class NotificationService
|
||||
public class NotificationService : IHostedService
|
||||
{
|
||||
private static NotificationService? _instance;
|
||||
|
||||
@ -37,6 +39,16 @@ public class NotificationService
|
||||
return _instance;
|
||||
}
|
||||
|
||||
public Task StartAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public Task StopAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
private HttpContent TransformData(INotificationData notificationData)
|
||||
{
|
||||
// using object type here so it serializes the interface correctly
|
||||
@ -84,4 +96,4 @@ public class NotificationService
|
||||
{
|
||||
await _notifierManager.SendNotificationToAllAsync(TransformData(notificationData));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user