Пример #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddLogging(builder =>
            {
                builder
                .AddConfiguration(Configuration.GetSection("Logging"))
                .AddFilter("Microsoft", LogLevel.Warning)
                .AddConsole();
            });
            services.AddSingleton <IConfiguration>(Configuration);

            var zkClient = new ZooKeeperClient(Configuration["ZooKeeperAddress"]);

            var path  = $"/{Configuration["RootNodeName"]}";
            var exist = zkClient.ExistsAsync(path).ConfigureAwait(false).GetAwaiter().GetResult();

            if (!exist)
            {
                zkClient.CreatePersistentAsync(path, "root").ConfigureAwait(false).GetAwaiter().GetResult();
            }

            services.AddSingleton <IZooKeeperClient>(zkClient);
            services.AddMvc(options =>
            {
                options.Filters.Add(typeof(ExceptionFilter));
            });

            services.AddSwaggerGen(option =>
            {
                option.SwaggerDoc("v1", new Info {
                    Title = "API Document", Version = "v1.0"
                });

                foreach (var file in Directory.GetFiles(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)).Where(w => w.EndsWith(".xml")))
                {
                    option.IncludeXmlComments(file);
                }
            });
        }