Exemplo n.º 1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseRouting();

            app.UseAuthentication();

            app.UseODataAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.Expand().Filter().Count().OrderBy();
                endpoints.MapODataRoute("odata", "odata", AppEdmModel.GetModel());
            });
        }
Exemplo n.º 2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            // 启用 Swagger 中间件,用于生成 JSON 端点
            app.UseSwagger();
            // 启用 Swagger UI
            app.UseSwaggerUI(options =>
            {
                options.SwaggerEndpoint("/swagger/v1/swagger.json", "API Doc");

                options.RoutePrefix = "api-docs";
            });


            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();

                // 在 OData 6.0.0 及以上的版本中默认无法使用这些功能,需要在此处指定启用
                endpoints.Select().Expand().Filter().OrderBy().MaxTop(100).Count();
                // 配置 OData 的路由前缀,用 http://*:5000/api/[controller] 访问 OData 控制器。
                endpoints.MapODataRoute("api", "api", AppEdmModel.GetModel());
            });

            // 在 UseEndpoints 中配置 OData,或调用 UseOData 配置 OData
            // app.UseOData("api", "api", AppEdmModel.GetModel());

            // 初始化示例数据
            using (var scpoe = app.ApplicationServices.CreateScope())
            {
                DataGenerator.InitSampleData(scpoe.ServiceProvider);
            }
        }