문제 설명
ASP.NET 5에 OData를 등록하는 방법 (How to register OData with ASP.NET 5)
ASP.NET 5 응용 프로그램이 있고 이 응용 프로그램과 함께 OData v4를 사용하고 싶습니다.
여기에 내가 시도한 것이 있습니다.
1.다음 nuget을 가져왔습니다. 패키지:
"Microsoft.AspNet.WebApi": "5.2.3",
"Microsoft.AspNet.OData": "5.7.0",
"Microsoft.AspNet.Hosting": "1.0.0‑rc1‑final"
2.Startup.Configure
메서드에서 호출
GlobalConfiguration.Configure(ConfigOData);
3.마지막으로 OData 구성입니다.
private static void ConfigOData(HttpConfiguration config)
{
ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
var EDM = builder.GetEdmModel();
//OData v4.0
config.MapODataServiceRoute("odata", "odata", EDM,
new DefaultODataPathHandler(),
conventions,
new DefaultODataBatchHandler(GlobalConfiguration.DefaultServer));
}
이제 OData 호출이 MVC의 라우팅 구성에 의해 처리되고 있습니다(아마도 ASP.NET 5에 OData를 제대로 등록하지 않았기 때문일 수 있습니다).
누군가 나를 도와줄 수 있습니까?
참조 솔루션
방법 1:
Here is how we can configure it with the ASP.NET Core RC2 OData.
namespace ODataSample
{
using Microsoft.AspNetCore.OData.Extensions;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using ODataSample.Models;
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddOData<ISampleService>();
}
public void Configure(IApplicationBuilder app)
{
app.UseOData("odata");
app.UseMvc();
}
}
}
Here is how you can try it yourself. You will need to have the .NET Core SDK installed.
git clone git@github.com:bigfont/WebApi.git
cd WebApi\vNext\src\Microsoft.AspNetCore.OData
dotnet restore
cd ..\..\samples\ODataSample.BigFont\
dotnet restore
dotnet run
This is the result at http://localhost:5000/odata
Links
(by Ayman、Shaun Luttin)