示例#1
0
    public static IServiceCollection AddServiceRegistry(this IServiceCollection services,
                                                        Action <ZaabeeConsulOptions> optionsFactory)
    {
        var options = new ZaabeeConsulOptions();

        optionsFactory(options);
        services.Configure(optionsFactory);
        services.TryAddSingleton <IConsulClient>(_ => new ConsulClient(x =>
        {
            x.Address    = options.ConsulAddress;
            x.Datacenter = options.Datacenter;
            x.Token      = options.Token;
            x.WaitTime   = options.WaitTime;
        }));
        services.AddHostedService <ServiceRegistry>();
        return(services);
    }
示例#2
0
 public ServiceRegistry(IConsulClient consulClient, IOptions <ZaabeeConsulOptions> options)
 {
     _consulClient = consulClient;
     _options      = options.Value;
 }