feat(AuthClient): implementiert IHostedService.
- Aktualisiert um AuthClient zu den Diensten als Hosted Service hinzuzufügen. - Der zugehörige Unit-Test wurde aktualisiert, um IHost anstelle von IServiceProvider zu verwenden, um gehostete Dienste testen zu können.
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
using DigitalData.Auth.Abstractions;
|
||||
using Microsoft.AspNetCore.SignalR.Client;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace DigitalData.Auth.Client;
|
||||
|
||||
public class AuthClient : IAuthClient, IAsyncDisposable
|
||||
public class AuthClient : IAuthClient, IHostedService
|
||||
{
|
||||
private readonly HubConnection _connection;
|
||||
|
||||
@@ -60,11 +61,4 @@ public class AuthClient : IAuthClient, IAsyncDisposable
|
||||
foreach (var publicKey in PublicKeys)
|
||||
await GetPublicKeyAsync(publicKey.Issuer, publicKey.Audience);
|
||||
}
|
||||
|
||||
public virtual async ValueTask DisposeAsync()
|
||||
{
|
||||
await _connection.StopAsync();
|
||||
await _connection.DisposeAsync();
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,14 @@ public static class DIExtensions
|
||||
.AddSingleton<IAuthClient, AuthClient>()
|
||||
.TryAddSingleton<HubConnectionBuilder>();
|
||||
|
||||
services.AddHostedService(sp =>
|
||||
{
|
||||
var client = sp.GetRequiredService<IAuthClient>() as AuthClient;
|
||||
if (client is not null)
|
||||
return client;
|
||||
else throw new Exception();
|
||||
});
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
@@ -29,6 +29,7 @@
|
||||
<PackageReference Include="DigitalData.Core.Abstractions" Version="3.3.0" />
|
||||
<PackageReference Include="DigitalData.Core.Security" Version="1.0.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="9.0.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="8.0.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
Reference in New Issue
Block a user