/// <summary> /// Adds OAuthServiceOptions to Service Collection /// </summary> /// <param name="services">Your Service Collection</param> /// <param name="config">Application Configuration</param> /// <returns>IServiceCollection for chaining</returns> public static IServiceCollection AddOAuthServiceOptions(this IServiceCollection services, IConfiguration config) { if (services == null) { throw new ArgumentNullException(nameof(services)); } if (config == null) { throw new ArgumentNullException(nameof(config)); } var oauthConfig = new OAuthConnectorOptions(config); var info = config.GetSingletonServiceInfo <SsoServiceInfo>(); var factory = new OAuthConnectorFactory(info, oauthConfig); services.AddSingleton(typeof(IOptions <OAuthServiceOptions>), factory.Create); return(services); }
public static IServiceCollection AddOAuthServiceOptions(this IServiceCollection services, IConfiguration config, string serviceName) { if (services == null) { throw new ArgumentNullException(nameof(services)); } if (string.IsNullOrEmpty(serviceName)) { throw new ArgumentNullException(nameof(serviceName)); } if (config == null) { throw new ArgumentNullException(nameof(config)); } OAuthConnectorOptions oauthConfig = new OAuthConnectorOptions(config); SsoServiceInfo info = config.GetRequiredServiceInfo <SsoServiceInfo>(serviceName); OAuthConnectorFactory factory = new OAuthConnectorFactory(info, oauthConfig); services.AddSingleton(typeof(IOptions <OAuthServiceOptions>), factory.Create); return(services); }