关于版本控制 dotnet core web api 业务逻辑层的任何建议?
我可以实现控制器的版本控制,它可以正常工作,如下所示。
下面是我的控制器逻辑。
[Route("/v{version:apiVersion}/common"), Produces("application/json")]
[ApiController]
public class CommonController : HeaderController
{
}
以下是我的启动版本控制注册。
public static void RegisterVersionServices(this IServiceCollection services)
{
services.AddVersionedApiExplorer(
options =>
{
options.GroupNameFormat = "'v'VV";
options.SubstituteApiVersionInUrl = true;
//options.SubstitutionFormat
});
services.AddApiVersioning(options =>
{
// Add the headers "api-supported-versions" and "api-deprecated-versions"
// This is better for discoverability
options.ReportApiVersions = true;
// AssumeDefaultVersionWhenUnspecified should only be enabled when supporting legacy services that did not previously
// support API versioning. Forcing existing clients to specify an explicit API version for an
// existing service introduces a breaking change. Conceptually, clients in this situation are
// bound to some API version of a service, but they don't know what it is and never explicit request it.
options.AssumeDefaultVersionWhenUnspecified = true;
options.DefaultApiVersion = new ApiVersion(1, 0);
options.ApiVersionReader = new UrlSegmentApiVersionReader();
options.Conventions.Add(new VersionByNamespaceConvention());
});
services.AddSingleton<IScopeInformation, ScopeInformation>();
}
正如我的想法,我可以为新层的业务层创建单独的文件夹。但是,如果有任何其他优雅的方式来实现业务逻辑版本控制,我不想弄乱我的可重用代码。