Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

How to define a Minimal Version (or a Range of versions) ?#1034

dvoituron started this conversation inIdeas
Discussion options

For the moment, we're using the following syntax to define which versions can be used by a controller.

[ApiController][ApiVersion(ApiVersions.V1_0)][ApiVersion(ApiVersions.V2_0)]publicclassMyController:ControllerBase{}

But when anew version is added, how is it possible to make it accessible to all controllers without having to add a new[ApiVersion(ApiVersions.V3_0)] attribute to the top ofall controllers?

Is it possible to indicate the version from which a controller is available?
Examples

  • [ApiVersionRange(From: ApiVersions.V1_0)]
  • [ApiVersionRange(From: ApiVersions.V1_0, To: ApiVersions.V3_0)]
You must be logged in to vote

Replies: 1 comment

Comment options

Out-of-the-box, the short answer is - no; however, there are many extensions to enable it. This type of solution is very specific to your application and cannot be easily genericized. API versionsmust be explicit, which is intrinsically why it isn't supported by default. Thestep is one of the biggest challenges. What should the step between versions be? A major version? A minor version? How about if the version is a date?

There are several possible solutions, but there is no universal answer that suites everyone (or it would be baked in). There are a number of options presented in discussions and (closed) issues.

At a high level, you have several options:

  • ExtendApiVersionAttribute orApiVersionsBaseAttribute
  • Roll your own attributes; API Versioning only cares aboutIApiVersionProvider
  • Useconventions
    • These can be convention only
    • These can be a convention using your own custom attributes
    • These can be explicitly configured via options

If all of your controllers are symmetrical and use the same set of versions, a custom convention (a laIControllerConvention) will have the least amount of churn as it will apply to all controllers. I suspect you'll find what you're looking for in the archives, but if not, I'm happy to help you flush out a more concrete solution.

Sidebar: The same is true for[ApiController]. You can apply[assembly: ApiController] and all controllers in the assembly will be considered API controllers so that you don't have to apply the attribute to every single controller. It also avoids the scenario where you forget to apply it.

You must be logged in to vote
0 replies
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
Ideas
Labels
None yet
2 participants
@dvoituron@commonsensesoftware

[8]ページ先頭

©2009-2025 Movatter.jp