Replies: 1 comment 2 replies
-
What makes you think that can't work? That would be perfect fine. The code is an implementation detail. There's no reason why two or more API versions cannot map to the same implementation. That behavior is actually part of the intended design. Applying an API version at the controller level implicitly applies all of those versions to the action level as well. In your first example, you applied the API versions directly at the action level. This is a supported scenario, but it's - honestly - kind of strange. An API typically is a collection of endpoints; for example, the Order or Customer API usually doesn't consist of one endpoint. A controller logically represents the API and all the endpoints that it consists of. When you use controllers, applying API versions at the controller level is usually what you want. If you interleave multiple versions with different implementations, you can use |
Beta Was this translation helpful? Give feedback.
-
Hi, team,
If a method in controller is the same for version 1.0 and version 2.0, how to avoid duplicate code for different version? Currently, I use 2 methods with same logic to implement API versioning.
Configuration:
This can't work, but this is kind of what I want:
I saw this discussion How do you use versioning with OData attribute routing? · dotnet/aspnet-api-versioning · Discussion #961 (github.com) has a workaround for version in url segment, but my project requires the version number to be included in the parameters.
However this can't work:
Appreciate for your help!
Beta Was this translation helpful? Give feedback.
All reactions