CSharp.Template/YuanXuan.IM.Api/CollectionExtensions/ApiVersioningServiceCollect...

38 lines
1.2 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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;
}
}
}