Input OData v4 in MVC 6

For the time being, I hope that someone an adventurer may have overcome this obstacle, since the current builds for MVC 6 running on ASP.Net v5.0 do not have any services that I can find to load OData in conveyor. I call app.UseMvc () and I can construct a routing convention, but I cannot define the HttpConfiguration object in the new process. I really hoped to work with combined MVC / WebApi in MVC 6, but OData v4 is a game changer.

If someone had experience and could point me in the right direction, please inform:

This may not help much, but here is my Startup class:

using System; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Http; using Microsoft.Data.OData; // Won't work, but needs using System.Web.OData.Builder; using Microsoft.Framework.DependencyInjection; namespace bmiAPI { public class Startup { public void Configure(IApplicationBuilder app) { app.UseWelcomePage(); app.UseMvc(); } public void ConfigureServices(IServiceCollection services) { services.AddMvc(); } } } 
+6
source share
1 answer

ASP.NET MVC 6 does not yet support OData. To host OData in ASP.NET, I would recommend using ASP.NET Web API 2.x, which supports both OData v3 and OData v4.

If you want to use OData in an ASP.NET 5 application, you can use the OWIN bridge to host the ASP.NET 5 API 2.x web interface, but it will not use MVC 6 anyway.

Then you will have a code like this (based on the above bridge):

 public void Configure(IApplicationBuilder app) { // Use OWIN bridge to map between ASP.NET 5 and Katana / OWIN app.UseAppBuilder(appBuilder => { // Some components will have dependencies that you need to populate in the IAppBuilder.Properties. // Here one example that maps the data protection infrastructure. appBuilder.SetDataProtectionProvider(app); // Configure Web API for self-host. HttpConfiguration config = new HttpConfiguration(); config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); appBuilder.UseWebApi(config); }; } 
+3
source

Source: https://habr.com/ru/post/979356/


All Articles