Ejemplo n.º 1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            services.AddMvcCore().SetCompatibilityVersion(CompatibilityVersion.Version_2_2).AddJsonFormatters();
            services.AddApiVersioning();
            services.AddVersionedApiExplorer(options => options.GroupNameFormat = "'v'VVV");

            // Swagger docs
            var descriptionProvider =
                services.BuildServiceProvider()
                .GetRequiredService <IApiVersionDescriptionProvider>();

            services.AddSwaggerGen(SwaggerOptionFactory.GetConfigurationOptions(descriptionProvider));

            services.AddSingleton <ITextProcessor, CapitalizeTextProcessor>();
            var isPersistent = Configuration.GetValue <bool>(StoreModeItemName);

            if (!isPersistent)
            {
                services.AddSingleton <IStore, InMemoryStore>();
            }
            else
            {
                var databaseFilename = Configuration.GetValue <string>(DatabaseFilenameItemName);
                services.AddSingleton <IDataRepository, DataRepository>(
                    provider => new DataRepository(databaseFilename));
                services.AddSingleton <IStore, PersistentStore>();
            }

            var logger = LoggerFactory.GetLogger();

            services.AddSingleton(logger);

            return(services.BuildServiceProvider());
        }
Ejemplo n.º 2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(
            IApplicationBuilder app,
            IHostingEnvironment env,
            IApiVersionDescriptionProvider descriptionProvider)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }

            app.UseRequestLogging();
            app.UseHttpsRedirection();
            app.UseMvc();

            app.UseSwagger();
            app.UseSwaggerUI(SwaggerOptionFactory.GetUiConfigurationOptions(descriptionProvider));
        }