1- using System ;
2- using System . Threading ;
1+ using System . Threading ;
32using System . Threading . Tasks ;
43using Microsoft . Extensions . Hosting ;
5- using Microsoft . Extensions . DependencyInjection ;
64using Lib . Net . Http . WebPush ;
75using Demo . AspNetCore . PushNotifications . Services . Abstractions ;
86
97namespace Demo . AspNetCore . PushNotifications . Services
108{
119 internal class PushNotificationsDequeuer : IHostedService
1210 {
13- private readonly IServiceProvider _serviceProvider ;
11+ private readonly IPushSubscriptionStoreAccessorProvider _subscriptionStoreAccessorProvider ;
1412 private readonly IPushNotificationsQueue _messagesQueue ;
1513 private readonly IPushNotificationService _notificationService ;
1614 private readonly CancellationTokenSource _stopTokenSource = new CancellationTokenSource ( ) ;
1715
1816 private Task _dequeueMessagesTask ;
1917
20- public PushNotificationsDequeuer ( IServiceProvider serviceProvider , IPushNotificationsQueue messagesQueue , IPushNotificationService notificationService )
18+ public PushNotificationsDequeuer ( IPushNotificationsQueue messagesQueue , IPushSubscriptionStoreAccessorProvider subscriptionStoreAccessorProvider , IPushNotificationService notificationService )
2119 {
22- _serviceProvider = serviceProvider ;
20+ _subscriptionStoreAccessorProvider = subscriptionStoreAccessorProvider ;
2321 _messagesQueue = messagesQueue ;
2422 _notificationService = notificationService ;
2523 }
@@ -46,11 +44,9 @@ private async Task DequeueMessagesAsync()
4644
4745 if ( ! _stopTokenSource . IsCancellationRequested )
4846 {
49- using ( IServiceScope serviceScope = _serviceProvider . CreateScope ( ) )
47+ using ( IPushSubscriptionStoreAccessor subscriptionStoreAccessor = _subscriptionStoreAccessorProvider . GetPushSubscriptionStoreAccessor ( ) )
5048 {
51- IPushSubscriptionStore subscriptionStore = serviceScope . ServiceProvider . GetRequiredService < IPushSubscriptionStore > ( ) ;
52-
53- await subscriptionStore . ForEachSubscriptionAsync ( ( PushSubscription subscription ) =>
49+ await subscriptionStoreAccessor . PushSubscriptionStore . ForEachSubscriptionAsync ( ( PushSubscription subscription ) =>
5450 {
5551 // Fire-and-forget
5652 _notificationService . SendNotificationAsync ( subscription , message , _stopTokenSource . Token ) ;
0 commit comments