28 lines
1.1 KiB
C#
28 lines
1.1 KiB
C#
using CM.Authentication.Abstractions;
|
|
using Microsoft.Extensions.Caching.Memory;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Logging;
|
|
using Microsoft.Extensions.Options;
|
|
|
|
namespace CM.Authentication;
|
|
|
|
public static class ServiceCollectionExtensions
|
|
{
|
|
public static IServiceCollection AddCakemailJwtTokenManager(this IServiceCollection services, string configurationSection = "Cakemail:Authentication")
|
|
{
|
|
services.AddOptions<AuthenticationOptions>()
|
|
.BindConfiguration(configurationSection);
|
|
|
|
services.AddSingleton<IJwtTokenManagerService>(serviceProvider =>
|
|
{
|
|
var options = serviceProvider.GetRequiredService<IOptions<AuthenticationOptions>>();
|
|
var httpClientFactory = serviceProvider.GetRequiredService<IHttpClientFactory>();
|
|
var memoryCache = serviceProvider.GetService<IMemoryCache>();
|
|
var logger = serviceProvider.GetService<ILogger<JwtTokenManagerService>>();
|
|
|
|
return new JwtTokenManagerService(options, httpClientFactory, memoryCache, logger);
|
|
});
|
|
|
|
return services;
|
|
}
|
|
} |