Beispiel #1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostEnvironment env, ILogger <Startup> logger)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseCors("CorsPolicy");

            app.UseODataBatching();

            var defaultODataBatchHander = new DefaultODataBatchHandler();

            defaultODataBatchHander.MessageQuotas.MaxNestingDepth           = 2;
            defaultODataBatchHander.MessageQuotas.MaxOperationsPerChangeset = 10;
            defaultODataBatchHander.MessageQuotas.MaxReceivedMessageSize    = 100;

            app.UseRouting();


            app.UseAuthorization();
            //app.UseMvc(o =>
            //{
            //    o.Select().Expand().Filter().OrderBy().Count();
            //    o.MapODataServiceRoute("odata", "odata", EdmHelpers.GetEdmModel(),
            //        ODataHelper.CreateDefaultODataBatchHander(2, 5, 100));
            //});
            app.UseEndpoints(endpoints =>
            {
                endpoints.Select().Expand().Filter().OrderBy().MaxTop(100).Count();
                endpoints.MapODataRoute("odata", "api", EdmHelpers.GetEdmModel(),
                                        ODataHelper.CreateDefaultODataBatchHander(2, 5, 100));
                endpoints.MapControllers();
            });


            // Enable middleware to serve generated Swagger as a JSON endpoint
            app.UseSwagger();

            // Enable middleware to serve swagger-ui assets (HTML, JS, CSS etc.)
            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "BookLoan Catalog API");
                c.RoutePrefix = string.Empty;
            }
                             );

            bool isInDockerContainer = (Environment.GetEnvironmentVariable("DOTNET_RUNNING_IN_CONTAINER") == "true");

            if (isInDockerContainer)
            {
                logger.LogInformation("Docker Db connection = " + Environment.GetEnvironmentVariable("DB_CONN_STR"));
            }

            using (var serviceScope = app.ApplicationServices.GetService <IServiceScopeFactory>().CreateScope())
            {
                var context = serviceScope.ServiceProvider.GetRequiredService <ApplicationDbContext>();
                context.Database.EnsureCreated(); // create database if not already created.

                //var config = app.ApplicationServices.GetService<AppConfiguration>();
                //Initialize(context);
            }
        }