Пример #1
0
 public IHttpClientBuilder Use <THandler>(params object[] args)
     where THandler : DelegatingHandler
 {
     HandlerDefs.Add(new HandlerDefinition {
         HandlerType = typeof(THandler), CtorArgs = args
     });
     return(this);
 }
Пример #2
0
        internal HttpMessageHandler Build()
        {
            var root = FinalHandlerDef != null
                ? (HttpMessageHandler)Activator.CreateInstance(FinalHandlerDef.HandlerType, FinalHandlerDef.CtorArgs)
                : new HttpClientHandler();

            FinalHandlerConfigurators.Each(x => x(root));

            return(HandlerDefs
                   .Reverse()
                   .Select(x => (DelegatingHandler)Activator.CreateInstance(x.HandlerType, x.CtorArgs))
                   .Aggregate(root, (current, next) =>
            {
                next.InnerHandler = current;
                return next;
            }));
        }