maliming
5 years ago
No known key found for this signature in database
GPG Key ID: 96224957E51C89E
7 changed files with
44 additions and
3 deletions
-
framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcOptions.cs
-
framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Conventions/AbpServiceConvention.cs
-
framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Versioning/HttpContextRequestedApiVersion.cs
-
framework/src/Volo.Abp.Http.Client.Web/Volo/Abp/Http/Client/Web/Conventions/AbpHttpClientProxyServiceConvention.cs
-
framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/ClientProxying/ClientProxyBase.cs
-
framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/ClientProxying/CurrentApiVersionInfo.cs
-
framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/ClientProxying/ICurrentApiVersionInfo.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; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -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; |
|
|
|
} |
|
|
|
|
|
|
|
@ -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; |
|
|
|
|
|
|
|
|
|
|
|
@ -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; |
|
|
|
} |
|
|
|
|
|
|
|
@ -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?
|
|
|
|
|
|
|
|
@ -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; |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -0,0 +1,10 @@ |
|
|
|
using System; |
|
|
|
|
|
|
|
namespace Volo.Abp.Http.Client.ClientProxying; |
|
|
|
|
|
|
|
public interface ICurrentApiVersionInfo |
|
|
|
{ |
|
|
|
ApiVersionInfo ApiVersionInfo { get; } |
|
|
|
|
|
|
|
IDisposable Change(ApiVersionInfo apiVersionInfo); |
|
|
|
} |