FalconSSO/FAuth/Extensions/Decryptor/ServiceCollentionExtent.cs

36 lines
1.5 KiB
C#

using System;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
namespace FAuth.Extensions.Decryptor
{
/// <summary>
/// 扩展IServiceCollection注册IUserTicketDryptor
/// </summary>
public static class ServiceCollentionExtent
{
/// <summary>
/// 通过显示配置注册IUserTicketDryptor
/// </summary>
/// <param name="service">服务集合</param>
/// <param name="action">配置选项的方法</param>
/// <returns>服务集合</returns>
public static IServiceCollection AddUserTicketDryptor(this IServiceCollection service,Action<UserTicketDecryptorOption> action) {
service.Configure<UserTicketDecryptorOption>(action);
service.AddSingleton<IUserTicketDryptor,UserTicketDryptor>();
return service;
}
/// <summary>
/// 通过提供配置节点信息注册IUserTicketDryptor
/// </summary>
/// <param name="services">服务集合</param>
/// <param name="section">配置文件节点</param>
/// <returns>服务集合</returns>
public static IServiceCollection AddUserTicketDryptor(this IServiceCollection services,IConfigurationSection section) {
services.Configure<UserTicketDecryptorOption>(section);
services.AddSingleton<IUserTicketDryptor,UserTicketDryptor>();
return services;
}
}
}