-
Notifications
You must be signed in to change notification settings - Fork 714
ApiExplorer migration #972
-
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?
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 2
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
-
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
.
Beta Was this translation helpful? Give feedback.
All reactions
-
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?
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1
-
Yes
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1