using Asp.Versioning; namespace LearningOfficer.OA.Mobile.Api.CollectionExtensions { /// /// Api版本控制服务扩展类 /// public static class ApiVersioningServiceCollectionExtensions { /// /// 添加Api版本控制服务 /// /// /// 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; } } }