public void Setup() { var container = new ServiceContainer(); container.AddHttpClient(); _sut = container.GetInstance <IHttpHandler>(); }
static void BasicUsage() { IServiceContainer container = new ServiceContainer(); //pool size 32 //configuration action is executed before each factory.Create() usage container.AddHttpClient(32, httpClient => { httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", "Token..."); }); //IHttpClientFactory is injectable IHttpClientFactory factory = container.Get <IHttpClientFactory>(); HttpClient client = factory.Create(); //use client here }
static void NamedUsage() { IServiceContainer container = new ServiceContainer(); //for service a //pool size 32 //configuration action is executed before each factory.Create() usage container.AddHttpClient("service-a", 16, httpClient => { httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", "Token-A..."); }); //for service b //pool size 32 //configuration action is executed before each factory.Create() usage container.AddHttpClient("service-b", 8, httpClient => { httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", "Token-B..."); }); //IHttpClientFactory is injectable IHttpClientFactory factory = container.Get <IHttpClientFactory>(); //get for service-a HttpClient clientA = factory.Create("service-a"); //get for service-b HttpClient clientB = factory.Create("service-b"); //use client here }