Esempio n. 1
0
            /// <summary>
            /// 将基于 jose-jwt 实现的 <see cref="IJwtService"/> 服务注入到给定的依赖服务集中。
            /// </summary>
            /// <param name="services"></param>
            /// <param name="options">为服务提供参数。</param>
            /// <returns></returns>
            /// <exception cref="ArgumentNullException">
            ///     <paramref name="services"/>为null
            ///     或
            ///     <paramref name="options"/>为null
            /// </exception>
            public static IServiceCollection AddJoseJwtService(this IServiceCollection services,
                                                               Action <JoseJwtServiceOptions> options = null)
            {
                if (services == null)
                {
                    throw new ArgumentNullException(nameof(services));
                }

                var optionObject = new JoseJwtServiceOptions();

                options?.Invoke(optionObject);

                return(services.AddSingleton <IJwtService, JoseJwtService>(_ => new JoseJwtService(optionObject)));
            }
Esempio n. 2
0
 /// <summary>
 /// 初始化 <see cref="JoseJwtService"/> 类的新实例。
 /// </summary>
 /// <param name="options">服务选项。</param>
 /// <exception cref="ArgumentNullException"></exception>
 public JoseJwtService(JoseJwtServiceOptions options)
 {
     _options = options ?? throw new ArgumentNullException(nameof(options));
 }