如何在ASP.NET 5中注册OData [英] How to register OData with ASP.NET 5
本文介绍了如何在ASP.NET 5中注册OData的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个ASP.NET 5应用程序,我想与它一起使用OData v4.
I have an ASP.NET 5 application and I would like to use OData v4 with it.
这是我尝试过的:
1.我导入了以下nuget包:
1.I imported the following nuget packages:
"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配置
3.And finally this is the OData configuration
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));
}
现在,MVC的路由配置正在处理OData调用(很可能是因为我没有在ASP.NET 5中正确注册OData).
Now the OData calls are being processed by the MVC's routing configuration (most probably because I did not register OData with ASP.NET 5 properly).
有人可以帮我吗?
推荐答案
以下是我们如何使用 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();
}
}
}
这是您自己尝试的方法.您需要安装 .NET Core SDK.
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
这是http://localhost:5000/odata
链接
- The repository in GitHub.
- The ISampleService in GitHub.
这篇关于如何在ASP.NET 5中注册OData的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文