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

ApiExplorer migration #972

Discussion options

I've migrated a project from .NET 5 to .NET 7, and also I've tried to migrate from Microsoft.AspNetCore.Mvc.Versioning.ApiExplorer 5.0.0 to Asp.Versioning.Mvc.ApiExplorer 7.0.0, but I cannot find an extension method for AddVersionedApiExplorer accepting a first argument of type IServiceCollection.

For example, the code below works with the old package but it doesn't work with the new package.

builder.Services.AddVersionedApiExplorer(setup => setup.GroupNameFormat = "'v'VVV");

How can I solve this? Is it a breaking change or is it on the roadmap?

You must be logged in to vote

Good question. There is now IApiVersioningBuilder that all subsequent configurations and services hang off of. The idea was to centralize everything API Versioning via one builder. Previously, there were several different configuration paths.

You have the correct package. The setup should now be:

builder.Services.AddApiVersioning()
 .AddApiExplorer(options => GroupNameFormat = "'v'VVV");

This configuration will implicitly imply:

builder.Services.AddApiVersioning()
 .AddMvc() // ← adds MVC Core with versioning support for controllers
 .AddApiExplorer(options => GroupNameFormat = "'v'VVV");

With the introduction of Minimal APIs, AddApiVersioning() ...

Replies: 1 comment 2 replies

Comment options

Good question. There is now IApiVersioningBuilder that all subsequent configurations and services hang off of. The idea was to centralize everything API Versioning via one builder. Previously, there were several different configuration paths.

You have the correct package. The setup should now be:

builder.Services.AddApiVersioning()
 .AddApiExplorer(options => GroupNameFormat = "'v'VVV");

This configuration will implicitly imply:

builder.Services.AddApiVersioning()
 .AddMvc() // ← adds MVC Core with versioning support for controllers
 .AddApiExplorer(options => GroupNameFormat = "'v'VVV");

With the introduction of Minimal APIs, AddApiVersioning() doesn't all the services you'll need. IApiVersioningBuilder.AddMvc() brings in the MVC Core features for controllers, but not the full MVC stack (which has confused some people). IApiVersioningBuilder.AddApiExplorer will implicitly bring in the necessary services if you haven't already. The Versioned part of the name was dropped to make it more succinct and is unambiguous since it is directly associated with the IApiVersioningBuilder.

You must be logged in to vote
2 replies
Comment options

Thank you for your feedback, Chris!

Just to confirm:
Do I need to include .AddMvc() only if I'm using controllers? (that's my case)
If I decide to use minimal APIs, can I avoid it?

Comment options

Yes

Answer selected by bsalmeida
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /