Esempio n. 1
0
        private static IServiceCollection AddFabio(this IServiceCollection services, FabioOptions fabioOptions,
                                                   HttpClientOptions httpClientOptions, Action <IServiceCollection> registerConsul)
        {
            registerConsul(services);
            services.AddSingleton(fabioOptions);

            if (httpClientOptions.Type?.ToLowerInvariant() == "fabio")
            {
                services.AddTransient <FabioMessageHandler>();
                services.AddHttpClient <IFabioHttpClient, FabioHttpClient>("fabio-http")
                .AddHttpMessageHandler <FabioMessageHandler>();


                services.RemoveInternalHttpClient();
                services.AddHttpClient <IHttpClient, FabioHttpClient>("fabio")
                .AddHttpMessageHandler <FabioMessageHandler>();
            }

            using var serviceProvider = services.BuildServiceProvider();
            var registration = serviceProvider.GetService <ServiceRegistration>();
            var tags         = GetFabioTags(registration.Name, fabioOptions.Service);

            if (registration.Tags is null)
            {
                registration.Tags = tags;
            }
            else
            {
                registration.Tags.AddRange(tags);
            }

            services.UpdateConsulRegistration(registration);

            return(services);
        }
Esempio n. 2
0
 public static IServiceCollection AddFabio(this IServiceCollection builder, FabioOptions fabioOptions,
                                           ConsulOptions consulOptions, HttpClientOptions httpClientOptions)
 => builder.AddFabio(fabioOptions, httpClientOptions, b => b.AddConsul(consulOptions, httpClientOptions));