-
Couldn't load subscription status.
- Fork 716
7.0.0 Preview 2 #916
-
This is the second and likely final preview release for ASP.NET Core with .NET 7.0 support. No additional work is planned, but there are some breaking changes that can be tried, tested, and discussed before promoting to the official release.
Features
ASP.NET Core
- Added
MapApiGroup()as a shortcut forMapGroup( "" ).WithApiVersionSet() - Metadata can now be added to groups (e.g.
RouteGroupBuilder) - Added injectable
VersionedEndpointRouteBuilderFactorydelegate
In Preview 2, metadata can now be applied even more succinctly.
var builder = WebApplication.CreateBuilder( args ); builder.Services.AddApiVersioning(); var app = builder.Build(); var orders = app.MapApiGroup(); // ← api group with optional name var v1 = orders.MapGroup( "/api/order" ).HasApiVersion( 1.0 ); // ← all endpoints in this group have 1.0 var v2 = orders.MapGroup( "/api/order" ).HasApiVersion( 2.0 ); // ← all endpoints in this group have 2.0 v1.MapGet( "/{id:int}", ( int id ) => new V1.Order() { Id = id, Customer = "John Doe" } ); v2.MapGet( "/{id:int}", ( int id ) => new V2.Order() { Id = id, Customer = "John Doe", Phone = "555-555-5555" } ); v2.MapDelete( "/{id:int}", ( int id ) => Results.NoContent() );
All of the previous methods of configuring metadata are still supported. For more examples, refer to the:
Fixes
- Use
404over400when versioning only by URL segment ([OData] /odata/v1/orders() gives 400 Bad Request "Unspecified API version" #911 )
Breaking Changes
The following are breaking changes from Preview 1. If you haven't added any customizations, these should all be source code compatible.
- Add group metadata validation to avoid common developer mistakes
- Replace
IApiVersionSetBuilderFactoryinterface with injectableApiVersionSetBuilderFactorydelegate - Refactor
RouteHandlerBuidlerextensions intoIEndpointRouteBuilderExtensions- This allows adding metadata on an endpoint or route group
If you have additional input or feedback, please provide them in the discussion. This will likely be the last time to discuss it before the release becomes official.
This discussion was created from the release 7.0.0 Preview 2.
Beta Was this translation helpful? Give feedback.