Browse Source

Compatible with API Versioning.

pull/11551/head
maliming 5 years ago
parent
commit
393ba91c03
No known key found for this signature in database GPG Key ID: 96224957E51C89E
  1. 3
      framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcOptions.cs
  2. 2
      framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Conventions/AbpServiceConvention.cs
  3. 2
      framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Versioning/HttpContextRequestedApiVersion.cs
  4. 2
      framework/src/Volo.Abp.Http.Client.Web/Volo/Abp/Http/Client/Web/Conventions/AbpHttpClientProxyServiceConvention.cs
  5. 6
      framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/ClientProxying/ClientProxyBase.cs
  6. 22
      framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/ClientProxying/CurrentApiVersionInfo.cs
  7. 10
      framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/ClientProxying/ICurrentApiVersionInfo.cs

3
framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcOptions.cs

@ -16,11 +16,14 @@ public class AbpAspNetCoreMvcOptions
public bool EnableRazorRuntimeCompilationOnDevelopment { get; set; }
public bool ChangeControllerModelApiExplorerGroupName { get; set; }
public AbpAspNetCoreMvcOptions()
{
ConventionalControllers = new AbpConventionalControllerOptions();
IgnoredControllersOnModelExclusion = new HashSet<Type>();
AutoModelValidation = true;
EnableRazorRuntimeCompilationOnDevelopment = true;
ChangeControllerModelApiExplorerGroupName = true;
}
}

2
framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Conventions/AbpServiceConvention.cs

@ -207,7 +207,7 @@ public class AbpServiceConvention : IAbpServiceConvention, ITransientDependency
protected virtual void ConfigureApiExplorer(ControllerModel controller)
{
if (controller.ApiExplorer.GroupName.IsNullOrEmpty())
if (Options.ChangeControllerModelApiExplorerGroupName && controller.ApiExplorer.GroupName.IsNullOrEmpty())
{
controller.ApiExplorer.GroupName = controller.ControllerName;
}

2
framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Versioning/HttpContextRequestedApiVersion.cs

@ -6,7 +6,7 @@ namespace Volo.Abp.AspNetCore.Mvc.Versioning;
public class HttpContextRequestedApiVersion : IRequestedApiVersion
{
public string Current => _httpContextAccessor.HttpContext?.GetRequestedApiVersion().ToString();
public string Current => _httpContextAccessor.HttpContext?.GetRequestedApiVersion()?.ToString();
private readonly IHttpContextAccessor _httpContextAccessor;

2
framework/src/Volo.Abp.Http.Client.Web/Volo/Abp/Http/Client/Web/Conventions/AbpHttpClientProxyServiceConvention.cs

@ -170,7 +170,7 @@ public class AbpHttpClientProxyServiceConvention : AbpServiceConvention
{
if (ControllerWithAttributeRoute.Contains(controller))
{
if (controller.ApiExplorer.GroupName.IsNullOrEmpty())
if (Options.ChangeControllerModelApiExplorerGroupName && controller.ApiExplorer.GroupName.IsNullOrEmpty())
{
controller.ApiExplorer.GroupName = controller.ControllerName;
}

6
framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/ClientProxying/ClientProxyBase.cs

@ -38,6 +38,7 @@ public class ClientProxyBase<TService> : ITransientDependency
protected IRemoteServiceHttpClientAuthenticator ClientAuthenticator => LazyServiceProvider.LazyGetRequiredService<IRemoteServiceHttpClientAuthenticator>();
protected ClientProxyRequestPayloadBuilder ClientProxyRequestPayloadBuilder => LazyServiceProvider.LazyGetRequiredService<ClientProxyRequestPayloadBuilder>();
protected ClientProxyUrlBuilder ClientProxyUrlBuilder => LazyServiceProvider.LazyGetRequiredService<ClientProxyUrlBuilder>();
protected ICurrentApiVersionInfo CurrentApiVersionInfo => LazyServiceProvider.LazyGetRequiredService<ICurrentApiVersionInfo>();
protected virtual async Task RequestAsync(string methodName, ClientProxyRequestTypeValue arguments = null)
{
@ -156,6 +157,11 @@ public class ClientProxyBase<TService> : ITransientDependency
protected virtual async Task<ApiVersionInfo> GetApiVersionInfoAsync(ClientProxyRequestContext requestContext)
{
if (CurrentApiVersionInfo.ApiVersionInfo != null)
{
return CurrentApiVersionInfo.ApiVersionInfo;
}
var apiVersion = await FindBestApiVersionAsync(requestContext);
//TODO: Make names configurable?

22
framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/ClientProxying/CurrentApiVersionInfo.cs

@ -0,0 +1,22 @@
using System;
using System.Threading;
using Volo.Abp.DependencyInjection;
namespace Volo.Abp.Http.Client.ClientProxying;
public class CurrentApiVersionInfo : ICurrentApiVersionInfo, ITransientDependency
{
public ApiVersionInfo ApiVersionInfo => _currentPrincipal.Value;
private readonly AsyncLocal<ApiVersionInfo> _currentPrincipal = new AsyncLocal<ApiVersionInfo>();
public virtual IDisposable Change(ApiVersionInfo apiVersionInfo)
{
var parent = ApiVersionInfo;
_currentPrincipal.Value = apiVersionInfo;
return new DisposeAction(() =>
{
_currentPrincipal.Value = parent;
});
}
}

10
framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/ClientProxying/ICurrentApiVersionInfo.cs

@ -0,0 +1,10 @@
using System;
namespace Volo.Abp.Http.Client.ClientProxying;
public interface ICurrentApiVersionInfo
{
ApiVersionInfo ApiVersionInfo { get; }
IDisposable Change(ApiVersionInfo apiVersionInfo);
}
Loading…
Cancel
Save