// 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.UseSwagger(); app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "OData Samples"); }); app.UseHttpsRedirection(); app.UseRouting(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); // 2. OData - Enable Dependency Injection on current routes endpoints.EnableDependencyInjection(builder => { // 3. OData - Enable operations for mapped entities builder.AddService(Microsoft.OData.ServiceLifetime.Singleton, typeof(IEdmModel), sp => EdmDtoConfig.GetEdmModel(app.ApplicationServices)) .AddService(Microsoft.OData.ServiceLifetime.Singleton, typeof(ODataUriResolver), sp => new StringAsEnumResolver()) .AddService(Microsoft.OData.ServiceLifetime.Singleton, typeof(ODataUriResolver), sp => new UnqualifiedCallAndEnumPrefixFreeResolver { EnableCaseInsensitive = true }); }); }); }
// 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(); // 2. OData - Enable Dependency Injection on current routes // endpoints.EnableDependencyInjection(); // 3. OData - Enable operations for all entities // endpoints.Select().Filter().OrderBy().Expand().MaxTop(100); //endpoints.EnableDependencyInjection(builder => //{ // var modelConfig = ODataMappings.GetEdmModel(app.ApplicationServices); // builder.AddService(Microsoft.OData.ServiceLifetime.Singleton, typeof(IEdmModel), sp => modelConfig) // .AddService(Microsoft.OData.ServiceLifetime.Singleton, typeof(ODataUriResolver), sp => new StringAsEnumResolver()) // .AddService(Microsoft.OData.ServiceLifetime.Singleton, typeof(ODataUriResolver), sp => new UnqualifiedCallAndEnumPrefixFreeResolver { EnableCaseInsensitive = true }); //}); endpoints.EnableDependencyInjection(builder => { builder.AddService(Microsoft.OData.ServiceLifetime.Singleton, typeof(IEdmModel), sp => EdmDtoConfig.GetEdmModel(app.ApplicationServices)) .AddService(Microsoft.OData.ServiceLifetime.Singleton, typeof(ODataUriResolver), sp => new StringAsEnumResolver()) .AddService(Microsoft.OData.ServiceLifetime.Singleton, typeof(ODataUriResolver), sp => new UnqualifiedCallAndEnumPrefixFreeResolver { EnableCaseInsensitive = true }); }); }); }