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

            if (!fabioOptions.Enabled || !builder.TryRegister(RegistryName))
            {
                return(builder);
            }

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

            using (var serviceProvider = builder.Services.BuildServiceProvider())
            {
                var registration = serviceProvider.GetService <AgentServiceRegistration>();
                registration.Tags = GetFabioTags(registration.Name, fabioOptions.Service);
                builder.Services.UpdateConsulRegistration(registration);
            }

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