Skip to content

Instantly share code, notes, and snippets.

@yzorg
Created September 15, 2020 15:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yzorg/62b7180c954a2ffaf8dd0dc89d79dca3 to your computer and use it in GitHub Desktop.
Save yzorg/62b7180c954a2ffaf8dd0dc89d79dca3 to your computer and use it in GitHub Desktop.
OData in Core 3.1 - route confusion

These folks seem to think [controller] works in [ODataRoutePrefix("todo")] public TodoController : ODataController

This seems to work:

This DOES NOT work, as far as I know:

  • [ODataRoutePrefix("[controller]")] public TodoController : ODataController
  • vs [Route("[controller]")][ApiController] public TodoController
    • generated REST API
    • CRUD API from scaffolding

But the latter would be a MAJOR UPGRADE to allow conventions to be used in routes.

Based on:

  • all the same benefits of convention-based routing, which ASP.NET Core team has convinced this community is a big win
  • it is VERY common the controller is named for entity set, just like REST APIs
  • web API generators emit [controller], makes it easier to change from [Route("[controller])"] to [ODataPrefix("[controller]")]
  • I can't get OData default convention-based routing to work in ASPNET Core. If convention-based routing for ~/api/todo(10) or ~/odata/todo(10) worked then this would not be nesssary.
@yzorg
Copy link
Author

yzorg commented Sep 15, 2020

My convention-based routing wasn't work because my controller methods take CancellationToken and sometimes use [FromServices] which looks to be fixed by recent PR: OData/WebApi#2168 .

@yzorg
Copy link
Author

yzorg commented Sep 16, 2020

The above PR addresses ActionSelector, which affects all routes, not just convention-based routes. Not sure if it affects batching, but I assume it does.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment