Example #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();
            }

            IEdmModel model = EdmModelBuilder.GetEdmModel();

            app.UseHttpsRedirection();

            app.UseRouting();

            app.UseAuthentication();
            app.UseAuthorization();

            app.UseMvc(routeBuilder =>
            {
                routeBuilder.Select().Expand().Filter().OrderBy();
                routeBuilder.MapODataServiceRoute("odata", "odata", model);
            });

            //app.UseEndpoints(endpoints =>
            //{
            //    //endpoints.MapControllers();
            //    endpoints.MapODataRoute("odataPrefix", "odata", model);
            //});
        }
Example #2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddDbContext <SecurityDbContext>(opt => opt.UseInMemoryDatabase("Example"));

            services.AddScoped <IAccountRepository, AccountRepository>();
            services.AddScoped <IUserRepository, UserRepository>();

            services.AddHostedService <DataSeedService>();
            services.AddSingleton <IMapper, Mapper>();

            services.AddOData(opts => opts
                              .Count()
                              .Filter()
                              .Expand()
                              .Select()
                              .OrderBy()
                              .SetMaxTop(null)
                              .AddModel("v{version}", EdmModelBuilder.GetEdmModel()));

            services
            .AddAuthentication("Bearer")
            .AddScheme <AuthenticationSchemeOptions, FakeAuthenticationHandler>("Bearer", null);

            services.AddControllers();

            services.AddApiVersioning(opts =>
            {
                opts.ReportApiVersions = true;
            });
        }
Example #3
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();
            }

            IEdmModel model = EdmModelBuilder.GetEdmModel();

            // Please add "UseODataBatching()" before "UseRouting()" to support OData $batch.
            app.UseODataBatching();

            app.UseRouting();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapODataRoute(
                    "nullPrefix", null,
                    b =>
                {
                    b.AddService(Microsoft.OData.ServiceLifetime.Singleton, sp => model);
                    b.AddService <ODataDeserializerProvider>(Microsoft.OData.ServiceLifetime.Singleton, sp => new EntityReferenceODataDeserializerProvider(sp));
                    b.AddService <IEnumerable <IODataRoutingConvention> >(Microsoft.OData.ServiceLifetime.Singleton,
                                                                          sp => ODataRoutingConventions.CreateDefaultWithAttributeRouting("nullPrefix", endpoints.ServiceProvider));
                });

                endpoints.MapODataRoute("odataPrefix", "odata", model);

                endpoints.MapODataRoute("myPrefix", "my/{data}", model);

                endpoints.MapODataRoute("msPrefix", "ms", model, new DefaultODataBatchHandler());
            });
        }
Example #4
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            var model = EdmModelBuilder.GetEdmModel();

            app.UseMvc(builder =>
            {
                builder.Select().Expand().Filter().OrderBy().MaxTop(100).Count();

                builder.MapRoute(
                    name: "default",
                    template: "",
                    defaults: new { controller = "Home", action = "Index" });
                builder.EnableDependencyInjection();

                builder.MapODataServiceRoute("odata1", "efcore", model);

                builder.MapODataServiceRoute("odata2", "inmem", model);

                builder.MapODataServiceRoute("odata3", "composite", EdmModelBuilder.GetCompositeModel());

                builder.MapODataServiceRoute("odata4", "odata", EdmModelBuilder.GetCustomerOrderModel());
            });
        }
        // 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.UseAuthorization();

            app.UseSwagger();
            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
            });

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

            app.EnsureMigrationOfContext <ContactDbContext>();

            app.UseODataMvc(EdmModelBuilder.GetEdmModel());
        }
        // 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.UseHttpsRedirection();

            app.UseRouting();

            app.UseAuthorization();

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


            app.UseMvc(builder =>
            {
                builder.Select().Expand().Filter().OrderBy().MaxTop(80).Count();

                builder.MapODataServiceRoute("odata", "odata", EdmModelBuilder.GetEdmModel());
            });
        }
Example #7
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env,
                              EdmModelBuilder modelBuilder,
                              AppDbContext context)
        {
            if (env.IsDevelopment())
            {
                app.UseBrowserLink();
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Error");
            }

            DbInitializer.Initialize(context, env);

            app.UseStaticFiles();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");

                // OData.
                routes.MapODataServiceRoute("ODataRoutes",
                                            "odata",
                                            modelBuilder.GetEdmModel(app.ApplicationServices));
            });
        }
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Error");
            }

            app.UseStaticFiles();

            app.UseRouting();

            app.UseAuthorization();

            app.UseMvc(routeBuilder =>
            {
                routeBuilder.Select().Expand().Filter().OrderBy().MaxTop(100).Count();
                routeBuilder.EnableDependencyInjection();
                IEdmModel model = EdmModelBuilder.GetEdmModel();
                routeBuilder.MapODataServiceRoute("odata", "odata", model);
            });
        }
Example #9
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddDbContext <MyDataContext>(opt => opt.UseLazyLoadingProxies().UseInMemoryDatabase("MyDataContextList"));

            IEdmModel model0 = EdmModelBuilder.GetEdmModel();
            IEdmModel model1 = EdmModelBuilder.GetEdmModelV1();
            IEdmModel model2 = EdmModelBuilder.GetEdmModelV2();

            services.AddControllers(options => {
                //{
                //    options.Conventions.Add(new MetadataApplicationModelConventionAttribute());
                //    options.Conventions.Add(new MetadataActionModelConvention());
            });

            /*services.AddConvention<MyConvention>();
             *
             * services.AddOData()
             *  .AddODataRouting(options => options
             *      .AddModel(EdmModelBuilder.GetEdmModel())
             *      .AddModel("v1", EdmModelBuilder.GetEdmModelV1())
             *      .AddModel("v2{data}", EdmModelBuilder.GetEdmModelV2()));
             *
             * services.AddODataFormatter();
             * services.AddODataQuery(options => options.Count().Filter().Expand().Select().OrderBy().SetMaxTop(5));
             */

            services.AddOData(opt => opt.Count().Filter().Expand().Select().OrderBy().SetMaxTop(5)
                              .AddModel(model0)
                              .AddModel("v1", model1)
                              .AddModel("v2{data}", model2, builder => builder.AddService <ODataBatchHandler, DefaultODataBatchHandler>(Microsoft.OData.ServiceLifetime.Singleton))
                              );
        }
Example #10
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();
            }

            IEdmModel model = EdmModelBuilder.GetEdmModel();

            app.UseRouting();

            app.UseAuthorization();

            app.UseODataBatching();

            app.UseEndpoints(endpoints =>
            {
                endpoints.Select().Expand().Filter().OrderBy().MaxTop(100).Count();

                endpoints.MapODataRoute("nullPrefix", null, model);

                endpoints.MapODataRoute("odataPrefix", "odata", model);

                endpoints.MapODataRoute("myPrefix", "my/{data}", model);

                endpoints.MapODataRoute("msPrefix", "ms", model, new DefaultODataBatchHandler());
            });

            app.UseSwagger();

            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("v1/swagger.json", "Test API (V1)");
            });
        }
Example #11
0
 public SelectExpandBinderTests()
 {
     _model       = EdmModelBuilder.GetEdmModel();
     _customer    = _model.SchemaElements.OfType <IEdmEntityType>().First(c => c.Name == "Customer");
     _vipCustomer = _model.SchemaElements.OfType <IEdmEntityType>().First(c => c.Name == "VipCustomer");
     _address     = _model.SchemaElements.OfType <IEdmComplexType>().First(c => c.Name == "Address");
     _customers   = _model.EntityContainer.FindEntitySet("Customers");
 }
Example #12
0
        private static HttpClient GetClient()
        {
            var config = new HttpConfiguration();

            config.MapODataServiceRoute("odata", "odata", EdmModelBuilder.GetEdmModel());

            return(new HttpClient(new HttpServer(config)));
        }
Example #13
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            string connectionString = @"Data Source=(LocalDb)\MSSQLLocalDB;Integrated Security=True;Initial Catalog=FilterDbContextTest";

            services.AddDbContext <FilterDbContext>(opt => opt.UseLazyLoadingProxies().UseSqlServer(connectionString));

            services.AddControllers()
            .AddOData(opt => opt.AddRouteComponents("odata", EdmModelBuilder.GetEdmModel()).EnableQueryFeatures());
        }
Example #14
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseMvc(builder => builder.MapODataServiceRoute("odata", "odata", EdmModelBuilder.GetEdmModel()));
        }
Example #15
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseOData(EdmModelBuilder.GetEdmModel());
        }
Example #16
0
        private static HttpClient GetCaseInsensitiveClient()
        {
            var config = new HttpConfiguration();

            config.EnableCaseInsensitive(true);
            config.EnableEnumPrefixFree(true);
            config.MapODataServiceRoute("odata3", "v3", EdmModelBuilder.GetEdmModel());
            return(new HttpClient(new HttpServer(config)));
        }
Example #17
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            #region Codes for backup and use to compare with preview design/implementation
            //services.AddControllers(options => {
            //{
            //    options.Conventions.Add(new MetadataApplicationModelConventionAttribute());
            //    options.Conventions.Add(new MetadataActionModelConvention());
            //});

            /*services.AddConvention<MyConvention>();
             *
             * services.AddOData()
             *  .AddODataRouting(options => options
             *      .AddModel(EdmModelBuilder.GetEdmModel())
             *      .AddModel("v1", EdmModelBuilder.GetEdmModelV1())
             *      .AddModel("v2{data}", EdmModelBuilder.GetEdmModelV2()));
             *
             * services.AddODataFormatter();
             * services.AddODataQuery(options => options.Count().Filter().Expand().Select().OrderBy().SetMaxTop(5));
             */
            #endregion

            services.AddDbContext <MyDataContext>(opt => opt.UseLazyLoadingProxies().UseInMemoryDatabase("MyDataContextList"));

            IEdmModel model0 = EdmModelBuilder.GetEdmModel();
            IEdmModel model1 = EdmModelBuilder.GetEdmModelV1();
            IEdmModel model2 = EdmModelBuilder.GetEdmModelV2();
            IEdmModel model3 = EdmModelBuilder.GetEdmModelV3();

            services.AddControllers()

            /*  If you want to remove $metadata endpoint, you can use ControllerFeatureProvider as follows
             * .ConfigureApplicationPartManager(manager =>
             * {
             *  manager.FeatureProviders.Remove(manager.FeatureProviders.OfType<ControllerFeatureProvider>().FirstOrDefault());
             *  manager.FeatureProviders.Add(new RemoveMetadataControllerFeatureProvider());
             * })
             *
             * or, remove MetadataRoutingConvention in AddOData as
             *   opt.Conventions.Remove(opt.Conventions.First(convention => convention is MetadataRoutingConvention));
             */
            .AddOData(opt => opt.Count().Filter().Expand().Select().OrderBy().SetMaxTop(5)
                      .AddRouteComponents(model0)
                      .AddRouteComponents("v1", model1)
                      .AddRouteComponents("v2{data}", model2, services => services.AddSingleton <ODataBatchHandler, DefaultODataBatchHandler>())
                      .AddRouteComponents("v3", model3)
                      .Conventions.Add(new MyConvention())
                      );

            services.AddSwaggerGen();
        }
Example #18
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseMvc(builder =>
            {
                builder.Select().Expand().Filter().OrderBy().MaxTop(100).Count();

                builder.MapODataServiceRoute("odata", "odata", EdmModelBuilder.GetEdmModel());
            });
        }
Example #19
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();
            }

            //      ApiDescriptionGroupCollectionProvider provider = new ApiDescriptionGroupCollectionProvider(null, null);
            //   DefaultApiDescriptionProvider provider = new DefaultApiDescriptionProvider(null, null, null, null, null);

            // ActionModel action = new ActionModel(null);
            //   ControllerModel m = new ControllerModel(null);
            ApiExplorerModel apiModel = new ApiExplorerModel();

            apiModel.IsVisible = true;
            ApiExplorerModel another = new ApiExplorerModel(apiModel);

            IEdmModel model = EdmModelBuilder.GetEdmModel();

            app.UseRouting();

            app.UseAuthorization();

            app.UseODataBatching();

            app.UseEndpoints(endpoints =>
            {
                endpoints.Select().Expand().Filter().OrderBy().MaxTop(100).Count();

                endpoints.MapODataRoute("nullPrefix", null, model);

                endpoints.MapODataRoute("odataPrefix", "odata", model);

                endpoints.MapODataRoute("myPrefix", "my/{data}", model);

                endpoints.MapODataRoute("msPrefix", "ms", model, new DefaultODataBatchHandler());
            });

            app.UseSwagger();

            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("v1/swagger.json", "Test API (V1)");
            });
        }
Example #20
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            IEdmModel model1 = EdmModelBuilder.GetEdmModel();
            IEdmModel model2 = EdmModelBuilder.BuildEdmModel();
            IEdmModel model3 = EnumsEdmModel.GetConventionModel();
            IEdmModel model4 = EnumsEdmModel.GetExplicitModel();

            services.AddControllers();

            services.AddOData(opt =>
                              opt
                              .AddModel(model1)
                              .AddModel("odata", model2)
                              .AddModel("v{version}", model1)
                              .AddModel("convention", model3)
                              .AddModel("explicit", model4))
            .AddConvention <MyEntitySetRoutingConvention>();
        }
Example #21
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers(options => {
                //{
                //    options.Conventions.Add(new MetadataApplicationModelConventionAttribute());
                //    options.Conventions.Add(new MetadataActionModelConvention());
            });

            // services.AddODataRouting();
            // services.AddODataRouting(model);

            services.AddConvention <MyConvention>();

            services.AddODataRouting(options => options
                                     .AddModel(EdmModelBuilder.GetEdmModel())
                                     .AddModel("v1", EdmModelBuilder.GetEdmModelV1())
                                     .AddModel("v2{data}", EdmModelBuilder.GetEdmModelV2()));
        }
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseHttpsRedirection();

            app.UseMvc(configureRoutes: routeBuilder =>
            {
                routeBuilder.Select().Expand().Filter().OrderBy().MaxTop(85).Count();

                routeBuilder.MapODataServiceRoute("odata", "odata", EdmModelBuilder.GetEdmModel());

                routeBuilder.EnableDependencyInjection();
            });
        }
Example #23
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            IEdmModel model1 = EdmModelBuilder.GetEdmModel();
            IEdmModel model2 = EdmModelBuilder.BuildEdmModel();
            IEdmModel model3 = EnumsEdmModel.GetConventionModel();
            IEdmModel model4 = EnumsEdmModel.GetExplicitModel();

            services.AddControllers().AddOData(opt =>
                                               opt
                                               .AddRouteComponents(model1)
                                               .AddRouteComponents("odata", model2)
                                               .AddRouteComponents("v{version}", model1)
                                               .AddRouteComponents("convention", model3)
                                               .AddRouteComponents("explicit", model4)
                                               .Conventions.Add(new MyEntitySetRoutingConvention()));

            services.AddSwaggerGen();
        }
Example #24
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            var model = EdmModelBuilder.GetEdmModel();

            app.UseMvc(builder =>
            {
                builder.Select().Expand().Filter().OrderBy().MaxTop(100).Count();

                builder.MapODataServiceRoute("odata1", "efcore", model);

                builder.MapODataServiceRoute("odata2", "inmem", model);

                builder.MapODataServiceRoute("odata3", "composite", EdmModelBuilder.GetCompositeModel());
            });
        }
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            IEdmModel model = EdmModelBuilder.GetEdmModel();

            /*
             * app.UseMvc(builder =>
             * {
             *  builder.Select().Expand().Filter().OrderBy().MaxTop(100).Count();
             *
             *  builder.MapODataServiceRoute("odata", "odata", model);
             * });*/

            app.UseRouting();
            app.UseEndpoints(endpoints =>
            {
                endpoints.MapODataServiceRoute("odata", "odata", model);

                endpoints.MapODataServiceRoute("odata2", "myprefix", model);
            });
        }
Example #26
0
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            app.UseDeveloperExceptionPage();
            app.UseStaticFiles();
            app.UseSpaStaticFiles();

            app.UseStaticFiles(new StaticFileOptions
            {
                FileProvider = new PhysicalFileProvider(Logger.LogDirectory),
                RequestPath  = "/logs"
            });

            app.UseDirectoryBrowser(new DirectoryBrowserOptions
            {
                FileProvider = new PhysicalFileProvider(Logger.LogDirectory),
                RequestPath  = "/logs"
            });

            app.UseExceptionHandler(err => err.HandleError(Logger));

            app.UseMvc(builder =>
            {
                builder.MapRoute(
                    name: "default",
                    template: "{controller}/{action=Index}/{id?}"
                    );

                builder.Select().Expand().Filter().OrderBy().MaxTop(100).Count();
                builder.MapODataServiceRoute("odata", "odata", EdmModelBuilder.GetEdmModel());
            });

            app.UseSpa(spa =>
            {
                spa.Options.SourcePath = "ClientApp";

                if (env.IsDevelopment())
                {
                    spa.UseAngularCliServer(npmScript: "start");
                }
            });
        }
Example #27
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            var model = EdmModelBuilder.GetEdmModel();

            app.UseMvc(builder =>
            {
                builder.Select().Expand().Filter().OrderBy().MaxTop(100).Count();

                builder.MapODataServiceRoute("odata1", "", model);
            });

            app.Run(async(context) =>
            {
                await context.Response.WriteAsync("Hello World!");
            });
        }
Example #28
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddDbContext <SecurityDbContext>(opt => opt.UseInMemoryDatabase("Example"));

            services.AddScoped <IAccountRepository, AccountRepository>();
            services.AddScoped <IUserRepository, UserRepository>();

            services.AddHostedService <DataSeedService>();
            services.AddSingleton <IMapper, Mapper>();

            services.AddOData(opts => opts
                              .Count()
                              .Filter()
                              .Expand()
                              .Select()
                              .OrderBy()
                              .SetMaxTop(null)
                              .AddModel(EdmModelBuilder.GetEdmModel()));

            services.AddControllers();
        }
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            using (var serviceScope = app.ApplicationServices.GetService <IServiceScopeFactory>().CreateScope())
            {
                var context = serviceScope.ServiceProvider.GetRequiredService <ApplicationDbContext>();
                SeedData.Initialize(context);
            }

            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.UseMvc(b =>
            {
                b.Select().Expand().Filter().OrderBy().MaxTop(100).Count();
                b.MapODataServiceRoute("Employees", "odata", EdmModelBuilder.GetEdmModel());
            });
        }
Example #30
0
        public static void Register(HttpConfiguration config)
        {
            var model = EdmModelBuilder.GetEdmModel();

            config.MapODataServiceRoute("odata", "odata", model);
        }