/// <summary> /// Create a new instance with recieveing an instance of <see cref="IJsonHttpContentConverter"/>, an inner handler and whether disposig the inner handler or not. /// </summary> /// <param name="converter">instance of <see cref="IJsonHttpContentConverter"/>.</param> /// <param name="handler">The inner handler.</param> /// <param name="disposeHandler">Whether disposing the inner handler or not.</param> public WebHookClient(IJsonHttpContentConverter converter, HttpMessageHandler handler, bool disposeHandler) { if (handler == null) { throw new ArgumentNullException(nameof(handler)); } _converter = converter ?? throw new ArgumentNullException(nameof(converter)); _client = new HttpClient(handler, disposeHandler); }
/// <summary> /// Create a new instance with recieveing an instance of <see cref="IJsonHttpContentConverter"/>. /// </summary> /// <param name="converter">The instance of <see cref="IJsonHttpContentConverter"/>.</param> public WebHookClient(IJsonHttpContentConverter converter) : this(converter, new HttpClientHandler(), true) { }
/// <summary> /// Create a new instance with recieveing an instance of <see cref="IJsonHttpContentConverter"/> and an inner handler. /// </summary> /// <param name="converter">instance of <see cref="IJsonHttpContentConverter"/>.</param> /// <param name="handler">The inner handler.</param> public WebHookClient(IJsonHttpContentConverter converter, HttpMessageHandler handler) : this(converter, handler, true) { }
/// <summary> /// Add <see cref="IWebHookClient"/> with an instance of <see cref="IJsonHttpContentConverter"/> to resolve an instance with DI. /// </summary> /// <param name="services"><see cref="IServiceCollection"/> to add services to.</param> /// <param name="converter">An instance of <see cref="IJsonHttpContentConverter"/>.</param> /// <returns>Added <see cref="IServiceCollection"/>.</returns> public static IServiceCollection AddSlackWebHookClient(this IServiceCollection services, IJsonHttpContentConverter converter) { if (services == null) { throw new ArgumentNullException(nameof(services)); } if (converter == null) { throw new ArgumentNullException(nameof(converter)); } services.AddSingleton(converter); services.AddTransient <IWebHookClient>(service => new WebHookClient(service.GetService <IJsonHttpContentConverter>())); return(services); }