Beispiel #1
0
        // This method gets called by the runtime. Use this method to add services to the container.

        // #tag::configureservices[]
        public void ConfigureServices(IServiceCollection services)
        {
            // Get logger factory to pass it along to the couchbase cluster.

            ILoggerFactory loggerFactory = services.BuildServiceProvider()
                                           .GetService <ILoggerFactory>();

            var options = new ClusterOptions()
            {
                Logging          = loggerFactory,
                UserName         = "******",
                Password         = "******",
                ConnectionString = "http://localhost"
            };

            // Bootstrap Cluster Object.
            var cluster = Cluster.ConnectAsync(options)
                          .GetAwaiter()
                          .GetResult();

            services.AddSingleton(typeof(ICluster), cluster);


            services.AddControllers().AddNewtonsoftJson(options => options.UseMemberCasing());
            services.AddMvc().AddNewtonsoftJson(options => options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore);

            //Swagger related
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new Microsoft.OpenApi.Models.OpenApiInfo {
                    Title = "Sample API", Version = "v1"
                });
            });
        }