Skip to content

Commit 1672a4c

Browse files
committed
Use HttpClientFactory. Resolves #5
1 parent fd6e613 commit 1672a4c

3 files changed

Lines changed: 9 additions & 8 deletions

File tree

Demo.AspNetCore.PushNotifications.Services.PushService/Demo.AspNetCore.PushNotifications.Services.PushService.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<ItemGroup>
77
<PackageReference Include="Lib.Net.Http.WebPush" Version="1.3.0" />
88
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="2.1.0-rc1-final" />
9+
<PackageReference Include="Microsoft.Extensions.Http" Version="2.1.0-rc1-final" />
910
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="2.1.0-rc1-final" />
1011
<PackageReference Include="Microsoft.Extensions.Options" Version="2.1.0-rc1-final" />
1112
</ItemGroup>

Demo.AspNetCore.PushNotifications.Services.PushService/PushServicePushNotificationService.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,15 @@ internal class PushServicePushNotificationService : IPushNotificationService
1818

1919
public string PublicKey { get { return _options.PublicKey; } }
2020

21-
public PushServicePushNotificationService(IOptions<PushNotificationServiceOptions> optionsAccessor, IVapidTokenCache vapidTokenCache, ILogger<PushServicePushNotificationService> logger)
21+
public PushServicePushNotificationService(IOptions<PushNotificationServiceOptions> optionsAccessor, IVapidTokenCache vapidTokenCache, PushServiceClient pushClient, ILogger<PushServicePushNotificationService> logger)
2222
{
2323
_options = optionsAccessor.Value;
2424

25-
_pushClient = new PushServiceClient
25+
_pushClient = pushClient;
26+
_pushClient.DefaultAuthentication = new VapidAuthentication(_options.PublicKey, _options.PrivateKey)
2627
{
27-
DefaultAuthentication = new VapidAuthentication(_options.PublicKey, _options.PrivateKey)
28-
{
29-
Subject = _options.Subject,
30-
TokenCache = vapidTokenCache
31-
}
28+
Subject = _options.Subject,
29+
TokenCache = vapidTokenCache
3230
};
3331

3432
_logger = logger;

Demo.AspNetCore.PushNotifications.Services.PushService/PushServiceServiceCollectionExtensions.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Microsoft.Extensions.DependencyInjection;
2+
using Lib.Net.Http.WebPush;
23
using Lib.Net.Http.WebPush.Authentication;
34
using Demo.AspNetCore.PushNotifications.Services.Abstractions;
45

@@ -10,7 +11,8 @@ public static IServiceCollection AddPushServicePushNotificationService(this ISer
1011
{
1112
services.AddMemoryCache();
1213
services.AddSingleton<IVapidTokenCache, MemoryVapidTokenCache>();
13-
services.AddSingleton<IPushNotificationService, PushServicePushNotificationService>();
14+
services.AddHttpClient<PushServiceClient>();
15+
services.AddTransient<IPushNotificationService, PushServicePushNotificationService>();
1416

1517
return services;
1618
}

0 commit comments

Comments
 (0)