我正在使用.NET 6。
我正在为我的 Web API 核心进行版本控制。当我在 Program.cs 中实现 IApiVersionDescriptionProvider 时,我陷入了困境。
因为在创建新项目ASP.NET Core Web API时,只有program.cs文件。(旧的.NET Core有Startup.cs和Program.cs)
请帮助我,谢谢大家这是我的代码
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ApiExplorer;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Options;
using Swashbuckle.AspNetCore.SwaggerGen;
using System.Reflection;
using VfcSolution.Application.User;
using VfcSolution.WebApi;
using VfcSolution.WebApi.VfcSolutionMapper;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddScoped<IUserRepository, OracleUserRepository>();
builder.Services.AddAutoMapper(typeof(VfcSolutionMappings));
builder.Services.AddApiVersioning(options =>
{
options.AssumeDefaultVersionWhenUnspecified = true;
options.DefaultApiVersion = new ApiVersion(1, 0);
options.ReportApiVersions = true;
});
builder.Services.AddVersionedApiExplorer(options => options.GroupNameFormat = "'v'VVV");
builder.Services.AddTransient<IConfigureOptions<SwaggerGenOptions>, ConfigureSwaggerOptions>();
builder.Services.AddSwaggerGen();
builder.Services.AddControllers();
var app = builder.Build();
// Configure the HTTP request …Run Code Online (Sandbox Code Playgroud)