Ejemplo n.º 1
0
        private static IFixerBuilder AddFabio(this IFixerBuilder builder, FabioOptions fabioOptions,
                                              HttpClientOptions httpClientOptions, Action <IFixerBuilder> 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>()
                .AddHttpMessageHandler <FabioMessageHandler>();
                builder.Services.AddHttpClient <IHttpClient, FabioHttpClient>()
                .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);
        }
Ejemplo n.º 2
0
 public static IFixerBuilder AddFabio(this IFixerBuilder builder, FabioOptions fabioOptions,
                                      ConsulOptions consulOptions, HttpClientOptions httpClientOptions)
 => builder.AddFabio(fabioOptions, httpClientOptions, b => b.AddConsul(consulOptions, httpClientOptions));