/// <summary>
 /// Initializes a new instance.
 /// </summary>
 /// <param name="host"></param>
 /// <param name="handler"></param>
 /// <param name="http"></param>
 /// <param name="logger"></param>
 public KHttpProtocol(IKHost <TNodeId> host, IKRequestHandler <TNodeId> handler, ITypedHttpClientFactory <KHttpProtocol <TNodeId> > http, ILogger logger)
 {
     this.host    = host ?? throw new ArgumentNullException(nameof(host));
     this.handler = handler ?? throw new ArgumentNullException(nameof(handler));
     this.http    = http ?? throw new ArgumentNullException(nameof(http));
     this.logger  = logger ?? throw new ArgumentNullException(nameof(logger));
 }
Exemple #2
0
        private static TClient AddTransientHelper <TClient, TImplementation>(IServiceProvider s, IHttpClientBuilder builder) where TClient : class where TImplementation : class, TClient
        {
            IHttpClientFactory httpClientFactory = s.GetRequiredService <IHttpClientFactory>();
            HttpClient         httpClient        = httpClientFactory.CreateClient(builder.Name);

            ITypedHttpClientFactory <TImplementation> typedClientFactory = s.GetRequiredService <ITypedHttpClientFactory <TImplementation> >();

            return(typedClientFactory.CreateClient(httpClient));
        }
Exemple #3
0
 public NameServiceController(ILogger <NameServiceController> logger,
                              IHttpClientFactory clientFactory,
                              ITypedHttpClientFactory <WeatherClientTyped> typedHttpClientFactory,
                              IReadOnlyPolicyRegistry <string> registry,
                              ILogger <ServiceFabricWeatherClientFactory> sflogger,
                              IServiceResolver serviceResolver)
 {
     _logger                         = logger;
     this.clientFactory              = clientFactory;
     _typedHttpClientFactory         = typedHttpClientFactory;
     _registry                       = registry;
     this.serviceResolver            = serviceResolver;
     this.serviceFabricClientFactory = new ServiceFabricWeatherClientFactory(clientFactory, ServiceFabricWeatherClientFactory.CreateHandlers(sflogger));
 }
Exemple #4
0
        internal static IHttpClientBuilder AddTypedClientCore <TClient>(this IHttpClientBuilder builder, bool validateSingleType)
            where TClient : class
        {
            ReserveClient(builder, typeof(TClient), builder.Name, validateSingleType);

            builder.Services.AddTransient <TClient>(s =>
            {
                IHttpClientFactory httpClientFactory = s.GetRequiredService <IHttpClientFactory>();
                HttpClient httpClient = httpClientFactory.CreateClient(builder.Name);

                ITypedHttpClientFactory <TClient> typedClientFactory = s.GetRequiredService <ITypedHttpClientFactory <TClient> >();
                return(typedClientFactory.CreateClient(httpClient));
            });

            return(builder);
        }
        internal static IHttpClientBuilder AddTypedClientCore <TClient, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TImplementation>(
            this IHttpClientBuilder builder, bool validateSingleType)
            where TClient : class
            where TImplementation : class, TClient
        {
            ReserveClient(builder, typeof(TClient), builder.Name, validateSingleType);

            builder.Services.AddTransient <TClient>(s =>
            {
                IHttpClientFactory httpClientFactory = s.GetRequiredService <IHttpClientFactory>();
                HttpClient httpClient = httpClientFactory.CreateClient(builder.Name);

                ITypedHttpClientFactory <TImplementation> typedClientFactory = s.GetRequiredService <ITypedHttpClientFactory <TImplementation> >();
                return(typedClientFactory.CreateClient(httpClient));
            });

            return(builder);
        }
Exemple #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TypedClientResolver{TInterface}"/> class.
 /// </summary>
 /// <param name="factory">The http client factory object</param>
 /// <param name="typedClient">The typedClient factory object</param>
 public TypedClientResolver(IHttpClientFactory factory, ITypedHttpClientFactory <TInterface> typedClient)
 {
     this.typedClient = typedClient ?? throw new ArgumentNullException("Unable to resolve typed client factory, please make sure it is configured with service collection");
     this.factory     = factory ?? throw new ArgumentNullException("Unable to resolve http client factory, please make sure it is configured with service");
 }