Browse Source

Improvements on versioning.

pull/122/head
Halil İbrahim Kalkan 9 years ago
parent
commit
7cb0a887e5
  1. 2
      src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AspNetCoreApiDescriptionModelProvider.cs
  2. 4
      src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/DynamicProxying/ApiDescriptionFinder.cs
  3. 26
      src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/DynamicProxying/DynamicHttpProxyInterceptor.cs
  4. 2
      src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/DynamicProxying/IApiDescriptionFinder.cs
  5. 2
      src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/RemoteServiceConfiguration.cs
  6. 5
      src/Volo.Abp.Http/Volo/Abp/Http/Modeling/ActionApiDescriptionModel.cs
  7. 5
      src/Volo.Abp.Http/Volo/Abp/Http/Modeling/ControllerApiDescriptionModel.cs

2
src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AspNetCoreApiDescriptionModelProvider.cs

@ -100,7 +100,7 @@ namespace Volo.Abp.AspNetCore.Mvc
private static string GetUniqueActionName(MethodInfo method) private static string GetUniqueActionName(MethodInfo method)
{ {
var methodNameBuilder = new StringBuilder(method.Name.RemovePostFix("Async")); var methodNameBuilder = new StringBuilder(method.Name);
var parameters = method.GetParameters(); var parameters = method.GetParameters();
if (parameters.Any()) if (parameters.Any())

4
src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/DynamicProxying/ApiDescriptionFinder.cs

@ -16,9 +16,9 @@ namespace Volo.Abp.Http.Client.DynamicProxying
_descriptionCache = descriptionCache; _descriptionCache = descriptionCache;
} }
public async Task<ActionApiDescriptionModel> FindActionAsync(RemoteServiceConfiguration proxyConfig, Type serviceType, MethodInfo method) public async Task<ActionApiDescriptionModel> FindActionAsync(string baseUrl, Type serviceType, MethodInfo method)
{ {
var apiDescription = await _descriptionCache.GetAsync(proxyConfig.BaseUrl); var apiDescription = await _descriptionCache.GetAsync(baseUrl);
//TODO: Cache finding? //TODO: Cache finding?

26
src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/DynamicProxying/DynamicHttpProxyInterceptor.cs

@ -94,9 +94,11 @@ namespace Volo.Abp.Http.Client.DynamicProxying
{ {
using (var client = _httpClientFactory.Create()) using (var client = _httpClientFactory.Create())
{ {
var proxyConfig = GetProxyConfig(); var baseUrl = GetBaseUrl();
var action = await _apiDescriptionFinder.FindActionAsync(proxyConfig, typeof(TService), invocation.Method); var version = GetVersion(); //TODO: Add version to the request (querystring, media type, path value or custom header!)
var url = proxyConfig.BaseUrl + UrlBuilder.GenerateUrlWithParameters(action, invocation.ArgumentsDictionary);
var action = await _apiDescriptionFinder.FindActionAsync(baseUrl, typeof(TService), invocation.Method);
var url = baseUrl + UrlBuilder.GenerateUrlWithParameters(action, invocation.ArgumentsDictionary);
var requestMessage = new HttpRequestMessage(action.GetHttpMethod(), url) var requestMessage = new HttpRequestMessage(action.GetHttpMethod(), url)
{ {
@ -128,16 +130,24 @@ namespace Volo.Abp.Http.Client.DynamicProxying
} }
} }
private RemoteServiceConfiguration GetProxyConfig() private string GetBaseUrl()
{ {
var clientConfig = _clientOptions.HttpClientProxies.GetOrDefault(typeof(TService)) var clientConfig = _clientOptions.HttpClientProxies.GetOrDefault(typeof(TService))
?? throw new AbpException($"Could not get DynamicHttpClientProxyConfig for {typeof(TService).FullName}."); ?? throw new AbpException($"Could not get DynamicHttpClientProxyConfig for {typeof(TService).FullName}.");
return _remoteServiceOptions.RemoteServices.GetOrDefault(clientConfig.RemoteServiceName) return _remoteServiceOptions.RemoteServices.GetOrDefault(clientConfig.RemoteServiceName)?.BaseUrl
?? _remoteServiceOptions.RemoteServices.Default ?? _remoteServiceOptions.RemoteServices.Default?.BaseUrl
?? throw new AbpException($"Could not get DynamicHttpClientProxyConfig for {typeof(TService).FullName}."); ?? throw new AbpException($"Could not find Base URL for {typeof(TService).FullName}.");
} }
private string GetVersion()
{
var clientConfig = _clientOptions.HttpClientProxies.GetOrDefault(typeof(TService))
?? throw new AbpException($"Could not get DynamicHttpClientProxyConfig for {typeof(TService).FullName}.");
return _remoteServiceOptions.RemoteServices.GetOrDefault(clientConfig.RemoteServiceName)?.Version
?? _remoteServiceOptions.RemoteServices.Default?.Version;
}
private async Task ThrowExceptionForResponseAsync(HttpResponseMessage response) private async Task ThrowExceptionForResponseAsync(HttpResponseMessage response)
{ {

2
src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/DynamicProxying/IApiDescriptionFinder.cs

@ -7,6 +7,6 @@ namespace Volo.Abp.Http.Client.DynamicProxying
{ {
public interface IApiDescriptionFinder public interface IApiDescriptionFinder
{ {
Task<ActionApiDescriptionModel> FindActionAsync(RemoteServiceConfiguration proxyConfig, Type serviceType, MethodInfo invocationMethod); Task<ActionApiDescriptionModel> FindActionAsync(string baseUrl, Type serviceType, MethodInfo invocationMethod);
} }
} }

2
src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/RemoteServiceConfiguration.cs

@ -4,6 +4,8 @@
{ {
public string BaseUrl { get; set; } public string BaseUrl { get; set; }
public string Version { get; set; }
public RemoteServiceConfiguration() public RemoteServiceConfiguration()
{ {

5
src/Volo.Abp.Http/Volo/Abp/Http/Modeling/ActionApiDescriptionModel.cs

@ -52,5 +52,10 @@ namespace Volo.Abp.Http.Modeling
{ {
return HttpMethodHelper.ConvertToHttpMethod(HttpMethod); return HttpMethodHelper.ConvertToHttpMethod(HttpMethod);
} }
public override string ToString()
{
return $"[ActionApiDescriptionModel {Name}]";
}
} }
} }

5
src/Volo.Abp.Http/Volo/Abp/Http/Modeling/ControllerApiDescriptionModel.cs

@ -73,5 +73,10 @@ namespace Volo.Abp.Http.Modeling
{ {
return Interfaces.Any(i => i.TypeAsString == interfaceType.GetFullNameWithAssemblyName()); return Interfaces.Any(i => i.TypeAsString == interfaceType.GetFullNameWithAssemblyName());
} }
public override string ToString()
{
return $"[ControllerApiDescriptionModel {ControllerName}]";
}
} }
} }
Loading…
Cancel
Save