public ApiHttpRequestHandlerBinding(IApiHttpHandlerFactory factory, Type handlerType) { _factory = factory ?? throw new ArgumentNullException(nameof(factory)); _handlerType = handlerType ?? throw new ArgumentNullException(nameof(handlerType)); }
/// <summary> /// Configure the API HTTP factory for the solution. /// </summary> /// <param name="builder">The dependency builder.</param> /// <param name="handlerFactory">Specify the handler factory.</param> /// <returns></returns> public static IDependencyBuilder ConfigureHttp(this IDependencyBuilder builder, IApiHttpHandlerFactory handlerFactory) { if (handlerFactory is null) { throw new ArgumentNullException(nameof(handlerFactory)); } ApiHttpFactory.Instance = new ApiHttpFactory(new System.Net.Http.HttpClient(), handlerFactory, new ApiHttpRequestHandlerBindingMap()); builder.BindInstance(ApiHttpFactory.Instance).Resolve <IApiHttpFactory>(); builder.BindFunction((ctx) => ApiHttpFactory.Instance.NewClient(ctx.Info.Key)).Resolve <IApiHttpClient>().InTransientScope(); return(builder); }
/// <summary> /// Create a new instance of the factory. /// </summary> /// <param name="httpClient">The <see cref="HttpClient"/> object that all <see cref="IApiHttpClient"/> will use.</param> /// <param name="handlerFactory">The handler factory that will be used to create the instances of <see cref="IApiHttpRequestHandler"/> from the <see cref="IApiHttpRequestHandlerBinding"/> bindings.</param> /// <param name="handlerMappings">The handler mapping that is used to store the handlers when getting a new client.</param> public ApiHttpFactory(HttpClient httpClient, IApiHttpHandlerFactory handlerFactory, IApiHttpRequestHandlerBindingMap handlerMappings) { _httpClient = httpClient ?? throw new ArgumentNullException(nameof(httpClient)); _handlerFactory = handlerFactory ?? throw new ArgumentNullException(nameof(handlerFactory)); _handlerMappings = handlerMappings ?? throw new ArgumentNullException(nameof(handlerMappings)); }
/// <summary> /// Configure the API HTTP factory for the solution. /// </summary> /// <param name="builder">The dependency builder.</param> /// <param name="useIocHttpHandlerFactory">Specify if to use the <see cref="DependencyApiHttpFactoryHandler"/>. If false, the default factory will be used, see <see cref="DefaultHttpHandlerFactory"/>. /// This factory uses runtime activation to create the handlers, <seealso cref="Runtime.Create"/>. /// </param> /// <returns></returns> public static IDependencyBuilder ConfigureHttp(this IDependencyBuilder builder, bool useIocHttpHandlerFactory) { IApiHttpHandlerFactory handlerFactory = useIocHttpHandlerFactory ? new DependencyApiHttpFactoryHandler() : new DefaultHttpHandlerFactory(Create.Instance); return(builder.ConfigureHttp(handlerFactory)); }