38 lines
1.2 KiB
C#
38 lines
1.2 KiB
C#
using Asp.Versioning;
|
||
|
||
namespace YuanXuan.IM.Api.CollectionExtensions
|
||
{
|
||
/// <summary>
|
||
/// Api版本控制服务扩展类
|
||
/// </summary>
|
||
public static class ApiVersioningServiceCollectionExtensions
|
||
{
|
||
/// <summary>
|
||
/// 添加Api版本控制服务
|
||
/// </summary>
|
||
/// <param name="services"></param>
|
||
/// <returns></returns>
|
||
public static IServiceCollection AddApiVersion(this IServiceCollection services)
|
||
{
|
||
services.AddApiVersioning(config =>
|
||
{
|
||
// 默认的Api版号
|
||
config.DefaultApiVersion = new ApiVersion(1, 0);
|
||
// 未指定Api版号的时候,使用默认版号
|
||
config.AssumeDefaultVersionWhenUnspecified = true;
|
||
// 是否在返回响应头中返回Api版本信息
|
||
config.ReportApiVersions = true;
|
||
|
||
}).AddApiExplorer(options =>
|
||
{
|
||
// Api 版本分组名称
|
||
options.GroupNameFormat = "'v'VVV";
|
||
// 未指定Api版号的时候,使用默认版号
|
||
options.SubstituteApiVersionInUrl = true;
|
||
});
|
||
|
||
return services;
|
||
}
|
||
}
|
||
}
|