Ejemplo n.º 1
0
        public void Configure(IServiceCollection services, IConfiguration configuration)
        {
            var couchbaseConfig       = configuration.GetSection("Couchbase");
            var contextBucketName     = couchbaseConfig["BucketName"];
            var contextBucketPassword = couchbaseConfig["Password"];
            var url = couchbaseConfig["Url"];

            InitCouchbaseCluster(contextBucketName, contextBucketPassword, url);

            var contextDriver = new CouchBaseDriver(ClusterHelper.GetBucket, contextBucketName);

            services.AddSingleton <IContextDriver>(contextDriver);
            services.AddSingleton <HealthCheck>(ctx =>
            {
                ctx.GetService <StaticCouchbaseDisposer>();
                return(new BucketConnectionHealthCheck(ClusterHelper.GetBucket, contextBucketName));
            });
            services.AddSingleton <StaticCouchbaseDisposer>();
        }
        public void Configure(IServiceCollection services, IConfiguration configuration)
        {
            var couchbaseConfig       = configuration.GetSection("Couchbase");
            var contextBucketName     = couchbaseConfig["BucketName"];
            var contextBucketPassword = couchbaseConfig["Password"];
            var url = couchbaseConfig["Url"];
            var healthCheckMaxLatency = Optional(couchbaseConfig["HealthCheck:MaxLatencyMilliseconds"]).Map(x => TimeSpan.FromMilliseconds(int.Parse(x))).IfNone(TimeSpan.FromSeconds(1));
            var healthCheckRetry      = Optional(couchbaseConfig["HealthCheck:RetryCount"]).Map(x => int.Parse(x)).IfNone(3);

            InitCouchbaseCluster(contextBucketName, contextBucketPassword, url);

            var contextDriver = new CouchBaseDriver(ClusterHelper.GetBucket, contextBucketName);

            services.AddSingleton <IContextDriver>(contextDriver);

            services.AddSingleton <HealthCheck>(ctx =>
            {
                ctx.GetService <StaticCouchbaseDisposer>();
                return(new BucketConnectionHealthCheck(ClusterHelper.GetBucket, contextBucketName, healthCheckMaxLatency, healthCheckRetry, ctx.GetService <ILogger <CouchBaseDriver> >()));
            });
            services.AddSingleton <StaticCouchbaseDisposer>();
        }
Ejemplo n.º 3
0
        public void Configure(IServiceCollection services, IConfiguration configuration)
        {
            var couchbaseConfig       = configuration.GetSection("Couchbase");
            var contextBucketName     = couchbaseConfig["BucketName"];
            var contextBucketPassword = couchbaseConfig["Password"];
            var serverUrl             = couchbaseConfig.GetSection("Url").Get <string>();
            var serverUrls            = couchbaseConfig.GetSection("Urls").Get <List <string> >();

            if (serverUrls == null || serverUrls.Count == 0)
            {
                serverUrls = new List <string>()
                {
                    serverUrl
                };
            }
            var healthCheckMaxLatency = Optional(couchbaseConfig["HealthCheck:MaxLatencyMilliseconds"]).Map(x => TimeSpan.FromMilliseconds(int.Parse(x))).IfNone(TimeSpan.FromSeconds(1));
            var healthCheckRetry      = Optional(couchbaseConfig["HealthCheck:RetryCount"]).Map(x => int.Parse(x)).IfNone(3);

            InitCouchbaseCluster(contextBucketName, contextBucketPassword, serverUrls);

            var contextDriver = new CouchBaseDriver(ClusterHelper.GetBucket, contextBucketName);

            services.AddSingleton <IContextDriver>(contextDriver);
            services.AddSingleton <CouchBaseDriver>(contextDriver);

            BucketConnectionHealthCheck healthCheck = null;

            services.AddHealthChecks().Add(new HealthCheckRegistration("CouchbaseConnection", (ctx) => {
                if (healthCheck != null)
                {
                    return(healthCheck);
                }
                ctx.GetService <StaticCouchbaseDisposer>();
                healthCheck = new BucketConnectionHealthCheck(ClusterHelper.GetBucket, contextBucketName, healthCheckMaxLatency, healthCheckRetry, ctx.GetService <ILogger <CouchBaseDriver> >());
                return(healthCheck);
            }, failureStatus: null, tags: Enumerable.Empty <string>()));
            services.AddSingleton <StaticCouchbaseDisposer>();
        }