How to register OData with ASP.NET 5

心已入冬 提交于 2019-12-04 02:29:24

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!