Exemplo n.º 1
0
        private static IDrexBuilder AddFabio(this IDrexBuilder builder, FabioOptions fabioOptions,
                                             HttpClientOptions httpClientOptions, Action <IDrexBuilder> 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 <ServiceRegistration>();
                var tags         = GetFabioTags(registration.Name, fabioOptions.Service);
                if (registration.Tags is null)
                {
                    registration.Tags = tags;
                }
                else
                {
                    registration.Tags.AddRange(tags);
                }

                builder.Services.UpdateConsulRegistration(registration);
            }

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