From 5499c87db0a2741f709776093080531153dacdfc Mon Sep 17 00:00:00 2001 From: Mon Date: Wed, 29 May 2019 10:36:46 +0800 Subject: [PATCH 1/5] use HttpClientFactory and Polly --- framework/Volo.Abp.sln | 2 +- ...etCoreTestDynamicProxyHttpClientFactory.cs | 9 ++- ...delRemoteServiceHttpClientAuthenticator.cs | 2 +- ...lectionDynamicHttpClientProxyExtensions.cs | 7 +++ .../Volo.Abp.Http.Client.csproj | 3 +- .../DefaultDynamicProxyHttpClientFactory.cs | 20 +++++-- .../DynamicHttpProxyInterceptor.cs | 58 +++++++++---------- .../IDynamicProxyHttpClientFactory.cs | 2 + 8 files changed, 65 insertions(+), 38 deletions(-) diff --git a/framework/Volo.Abp.sln b/framework/Volo.Abp.sln index be77f0ab24..3d0beab360 100644 --- a/framework/Volo.Abp.sln +++ b/framework/Volo.Abp.sln @@ -1,4 +1,4 @@ -Microsoft Visual Studio Solution File, Format Version 12.00 +Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 VisualStudioVersion = 15.0.28307.168 MinimumVisualStudioVersion = 10.0.40219.1 diff --git a/framework/src/Volo.Abp.AspNetCore.TestBase/Volo/Abp/AspNetCore/TestBase/DynamicProxying/AspNetCoreTestDynamicProxyHttpClientFactory.cs b/framework/src/Volo.Abp.AspNetCore.TestBase/Volo/Abp/AspNetCore/TestBase/DynamicProxying/AspNetCoreTestDynamicProxyHttpClientFactory.cs index e0253f8f8b..e8463e16cc 100644 --- a/framework/src/Volo.Abp.AspNetCore.TestBase/Volo/Abp/AspNetCore/TestBase/DynamicProxying/AspNetCoreTestDynamicProxyHttpClientFactory.cs +++ b/framework/src/Volo.Abp.AspNetCore.TestBase/Volo/Abp/AspNetCore/TestBase/DynamicProxying/AspNetCoreTestDynamicProxyHttpClientFactory.cs @@ -8,15 +8,20 @@ namespace Volo.Abp.AspNetCore.TestBase.DynamicProxying public class AspNetCoreTestDynamicProxyHttpClientFactory : IDynamicProxyHttpClientFactory, ITransientDependency { private readonly ITestServerAccessor _testServerAccessor; + private readonly IHttpClientFactory _httpClientFactory; - public AspNetCoreTestDynamicProxyHttpClientFactory(ITestServerAccessor testServerAccessor) - { + public AspNetCoreTestDynamicProxyHttpClientFactory(ITestServerAccessor testServerAccessor, IHttpClientFactory httpClientFactory) { _testServerAccessor = testServerAccessor; + _httpClientFactory = httpClientFactory; } public HttpClient Create() { return _testServerAccessor.Server.CreateClient(); } + + public HttpClient Create(string name) { + return Create(); + } } } diff --git a/framework/src/Volo.Abp.Http.Client.IdentityModel/Volo/Abp/Http/Client/IdentityModel/IdentityModelRemoteServiceHttpClientAuthenticator.cs b/framework/src/Volo.Abp.Http.Client.IdentityModel/Volo/Abp/Http/Client/IdentityModel/IdentityModelRemoteServiceHttpClientAuthenticator.cs index 91d1c4cb9b..eab45ca96b 100644 --- a/framework/src/Volo.Abp.Http.Client.IdentityModel/Volo/Abp/Http/Client/IdentityModel/IdentityModelRemoteServiceHttpClientAuthenticator.cs +++ b/framework/src/Volo.Abp.Http.Client.IdentityModel/Volo/Abp/Http/Client/IdentityModel/IdentityModelRemoteServiceHttpClientAuthenticator.cs @@ -28,7 +28,7 @@ namespace Volo.Abp.Http.Client.IdentityModel var accessToken = await GetAccessTokenFromHttpContextOrNullAsync(); if (accessToken != null) { - context.Client.SetBearerToken(accessToken); + context.Request.SetBearerToken(accessToken); return; } } diff --git a/framework/src/Volo.Abp.Http.Client/Microsoft/Extensions/DependencyInjection/ServiceCollectionDynamicHttpClientProxyExtensions.cs b/framework/src/Volo.Abp.Http.Client/Microsoft/Extensions/DependencyInjection/ServiceCollectionDynamicHttpClientProxyExtensions.cs index 7689e94494..21212ee16a 100644 --- a/framework/src/Volo.Abp.Http.Client/Microsoft/Extensions/DependencyInjection/ServiceCollectionDynamicHttpClientProxyExtensions.cs +++ b/framework/src/Volo.Abp.Http.Client/Microsoft/Extensions/DependencyInjection/ServiceCollectionDynamicHttpClientProxyExtensions.cs @@ -3,6 +3,7 @@ using System.Linq; using System.Reflection; using Castle.DynamicProxy; using JetBrains.Annotations; +using Polly; using Volo.Abp; using Volo.Abp.Castle.DynamicProxy; using Volo.Abp.Http.Client; @@ -105,6 +106,12 @@ namespace Microsoft.Extensions.DependencyInjection { options.HttpClientProxies[type] = new DynamicHttpClientProxyConfig(type, remoteServiceConfigurationName); }); + + //use IHttpClientFactory and polly + services.AddHttpClient(remoteServiceConfigurationName) + .AddTransientHttpErrorPolicy(builder => + // retry 3 times + builder.WaitAndRetryAsync(3, i => TimeSpan.FromSeconds(Math.Pow(2, i)))); var interceptorType = typeof(DynamicHttpProxyInterceptor<>).MakeGenericType(type); services.AddTransient(interceptorType); diff --git a/framework/src/Volo.Abp.Http.Client/Volo.Abp.Http.Client.csproj b/framework/src/Volo.Abp.Http.Client/Volo.Abp.Http.Client.csproj index f6afd53f1d..1c7f727e18 100644 --- a/framework/src/Volo.Abp.Http.Client/Volo.Abp.Http.Client.csproj +++ b/framework/src/Volo.Abp.Http.Client/Volo.Abp.Http.Client.csproj @@ -1,4 +1,4 @@ - + @@ -15,6 +15,7 @@ + diff --git a/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/DynamicProxying/DefaultDynamicProxyHttpClientFactory.cs b/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/DynamicProxying/DefaultDynamicProxyHttpClientFactory.cs index 6c827f5237..e4aad53a11 100644 --- a/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/DynamicProxying/DefaultDynamicProxyHttpClientFactory.cs +++ b/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/DynamicProxying/DefaultDynamicProxyHttpClientFactory.cs @@ -1,13 +1,25 @@ using System.Net.Http; using Volo.Abp.DependencyInjection; -namespace Volo.Abp.Http.Client.DynamicProxying +namespace Volo.Abp.Http.Client.DynamicProxying { - public class DefaultDynamicProxyHttpClientFactory : IDynamicProxyHttpClientFactory, ITransientDependency + public class DefaultDynamicProxyHttpClientFactory : IDynamicProxyHttpClientFactory, ITransientDependency { - public HttpClient Create() + private readonly IHttpClientFactory _httpClientFactory; + + public DefaultDynamicProxyHttpClientFactory(IHttpClientFactory httpClientFactory) + { + _httpClientFactory = httpClientFactory; + } + + public HttpClient Create() + { + return _httpClientFactory.CreateClient(); + } + + public HttpClient Create(string name) { - return new HttpClient(); + return _httpClientFactory.CreateClient(name); } } } \ No newline at end of file diff --git a/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/DynamicProxying/DynamicHttpProxyInterceptor.cs b/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/DynamicProxying/DynamicHttpProxyInterceptor.cs index 1a79d4308a..5b200daf85 100644 --- a/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/DynamicProxying/DynamicHttpProxyInterceptor.cs +++ b/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/DynamicProxying/DynamicHttpProxyInterceptor.cs @@ -128,41 +128,41 @@ namespace Volo.Abp.Http.Client.DynamicProxying private async Task MakeRequestAsync(IAbpMethodInvocation invocation) { - using (var client = HttpClientFactory.Create()) - { - var clientConfig = ClientOptions.HttpClientProxies.GetOrDefault(typeof(TService)) ?? throw new AbpException($"Could not get DynamicHttpClientProxyConfig for {typeof(TService).FullName}."); - var remoteServiceConfig = RemoteServiceOptions.RemoteServices.GetConfigurationOrDefault(clientConfig.RemoteServiceName); + var clientConfig = ClientOptions.HttpClientProxies.GetOrDefault(typeof(TService)) ?? throw new AbpException($"Could not get DynamicHttpClientProxyConfig for {typeof(TService).FullName}."); + var remoteServiceConfig = RemoteServiceOptions.RemoteServices.GetConfigurationOrDefault(clientConfig.RemoteServiceName); - var action = await ApiDescriptionFinder.FindActionAsync(remoteServiceConfig.BaseUrl, typeof(TService), invocation.Method); - var apiVersion = GetApiVersionInfo(action); - var url = remoteServiceConfig.BaseUrl + UrlBuilder.GenerateUrlWithParameters(action, invocation.ArgumentsDictionary, apiVersion); + var client = HttpClientFactory.Create(clientConfig.RemoteServiceName); - var requestMessage = new HttpRequestMessage(action.GetHttpMethod(), url) - { - Content = RequestPayloadBuilder.BuildContent(action, invocation.ArgumentsDictionary, JsonSerializer, apiVersion) - }; - - AddHeaders(invocation, action, requestMessage, apiVersion); - - await ClientAuthenticator.Authenticate( - new RemoteServiceHttpClientAuthenticateContext( - client, - requestMessage, - remoteServiceConfig, - clientConfig.RemoteServiceName - ) - ); + var action = await ApiDescriptionFinder.FindActionAsync(remoteServiceConfig.BaseUrl, typeof(TService), invocation.Method); + var apiVersion = GetApiVersionInfo(action); + var url = remoteServiceConfig.BaseUrl + UrlBuilder.GenerateUrlWithParameters(action, invocation.ArgumentsDictionary, apiVersion); - var response = await client.SendAsync(requestMessage, GetCancellationToken()); + var requestMessage = new HttpRequestMessage(action.GetHttpMethod(), url) + { + Content = RequestPayloadBuilder.BuildContent(action, invocation.ArgumentsDictionary, JsonSerializer, apiVersion) + }; - if (!response.IsSuccessStatusCode) - { - await ThrowExceptionForResponseAsync(response); - } + AddHeaders(invocation, action, requestMessage, apiVersion); - return await response.Content.ReadAsStringAsync(); + await ClientAuthenticator.Authenticate( + new RemoteServiceHttpClientAuthenticateContext( + client, + requestMessage, + remoteServiceConfig, + clientConfig.RemoteServiceName + ) + ); + + var response = await client.SendAsync(requestMessage, GetCancellationToken()); + + if (!response.IsSuccessStatusCode) + { + await ThrowExceptionForResponseAsync(response); } - } + + return await response.Content.ReadAsStringAsync(); + } + private ApiVersionInfo GetApiVersionInfo(ActionApiDescriptionModel action) { diff --git a/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/DynamicProxying/IDynamicProxyHttpClientFactory.cs b/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/DynamicProxying/IDynamicProxyHttpClientFactory.cs index aaf821d0f9..1cc90672a1 100644 --- a/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/DynamicProxying/IDynamicProxyHttpClientFactory.cs +++ b/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/DynamicProxying/IDynamicProxyHttpClientFactory.cs @@ -5,5 +5,7 @@ namespace Volo.Abp.Http.Client.DynamicProxying public interface IDynamicProxyHttpClientFactory { HttpClient Create(); + + HttpClient Create(string name); } } \ No newline at end of file From 99c33788bce77a1c7d8f35db662d355b4557f02a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Wed, 12 Jun 2019 16:06:32 +0300 Subject: [PATCH 2/5] Added empty docs --- docs/en/Aspect-Oriented-Programming.md | 3 +++ docs/en/Data-Filtering.md | 3 +++ docs/en/Specifications.md | 3 +++ 3 files changed, 9 insertions(+) create mode 100644 docs/en/Aspect-Oriented-Programming.md create mode 100644 docs/en/Data-Filtering.md create mode 100644 docs/en/Specifications.md diff --git a/docs/en/Aspect-Oriented-Programming.md b/docs/en/Aspect-Oriented-Programming.md new file mode 100644 index 0000000000..76a23daa8f --- /dev/null +++ b/docs/en/Aspect-Oriented-Programming.md @@ -0,0 +1,3 @@ +## Dynamic Proxying / Interceptors + +TODO \ No newline at end of file diff --git a/docs/en/Data-Filtering.md b/docs/en/Data-Filtering.md new file mode 100644 index 0000000000..284f74918a --- /dev/null +++ b/docs/en/Data-Filtering.md @@ -0,0 +1,3 @@ +# Data Filtering + +TODO \ No newline at end of file diff --git a/docs/en/Specifications.md b/docs/en/Specifications.md new file mode 100644 index 0000000000..ea4f140e95 --- /dev/null +++ b/docs/en/Specifications.md @@ -0,0 +1,3 @@ +# Specifications + +TODO! \ No newline at end of file From 523f605d351c0cc2f7b44536888c0a1aeca07a38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Wed, 12 Jun 2019 16:28:57 +0300 Subject: [PATCH 3/5] Added empty docs. --- docs/en/AspNetCore/Tag-Helpers.md | 3 --- docs/en/AspNetCore/Tag-Helpers/Dynamic-Forms.md | 3 +++ docs/en/{Tag-Helpers.md => AspNetCore/Tag-Helpers/Index.md} | 0 docs/en/Caching.md | 3 +++ docs/en/CorrelationId.md | 3 +++ docs/en/docs-nav.json | 2 +- 6 files changed, 10 insertions(+), 4 deletions(-) delete mode 100644 docs/en/AspNetCore/Tag-Helpers.md create mode 100644 docs/en/AspNetCore/Tag-Helpers/Dynamic-Forms.md rename docs/en/{Tag-Helpers.md => AspNetCore/Tag-Helpers/Index.md} (100%) create mode 100644 docs/en/Caching.md create mode 100644 docs/en/CorrelationId.md diff --git a/docs/en/AspNetCore/Tag-Helpers.md b/docs/en/AspNetCore/Tag-Helpers.md deleted file mode 100644 index 4949a3ec63..0000000000 --- a/docs/en/AspNetCore/Tag-Helpers.md +++ /dev/null @@ -1,3 +0,0 @@ -# Tag Helpers - -TODO \ No newline at end of file diff --git a/docs/en/AspNetCore/Tag-Helpers/Dynamic-Forms.md b/docs/en/AspNetCore/Tag-Helpers/Dynamic-Forms.md new file mode 100644 index 0000000000..6d700f030d --- /dev/null +++ b/docs/en/AspNetCore/Tag-Helpers/Dynamic-Forms.md @@ -0,0 +1,3 @@ +## Dynamic Forms + +This is not documented yet. You can see a [demo](http://bootstrap-taghelpers.abp.io/Components/DynamicForms) for now. \ No newline at end of file diff --git a/docs/en/Tag-Helpers.md b/docs/en/AspNetCore/Tag-Helpers/Index.md similarity index 100% rename from docs/en/Tag-Helpers.md rename to docs/en/AspNetCore/Tag-Helpers/Index.md diff --git a/docs/en/Caching.md b/docs/en/Caching.md new file mode 100644 index 0000000000..f7d9c52407 --- /dev/null +++ b/docs/en/Caching.md @@ -0,0 +1,3 @@ +# Caching + +TODO \ No newline at end of file diff --git a/docs/en/CorrelationId.md b/docs/en/CorrelationId.md new file mode 100644 index 0000000000..99bcd448f4 --- /dev/null +++ b/docs/en/CorrelationId.md @@ -0,0 +1,3 @@ +# Correlation ID + +TODO \ No newline at end of file diff --git a/docs/en/docs-nav.json b/docs/en/docs-nav.json index eaee22e59a..27ebb86a2c 100644 --- a/docs/en/docs-nav.json +++ b/docs/en/docs-nav.json @@ -218,7 +218,7 @@ }, { "text": "Tag Helpers", - "path": "Tag-Helpers.md" + "path": "AspNetCore/Tag-Helpers/Index.md" }, { "text": "Theming", From 64352b6df35986e95713855ef7b0bdb5bbdf6d75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Wed, 12 Jun 2019 19:15:36 +0300 Subject: [PATCH 4/5] Added UseIIS --- .../BookStore/src/Acme.BookStore.Web/Acme.BookStore.Web.csproj | 1 + samples/BookStore/src/Acme.BookStore.Web/Program.cs | 1 + 2 files changed, 2 insertions(+) diff --git a/samples/BookStore/src/Acme.BookStore.Web/Acme.BookStore.Web.csproj b/samples/BookStore/src/Acme.BookStore.Web/Acme.BookStore.Web.csproj index a6e1fb1b77..b638a6a114 100644 --- a/samples/BookStore/src/Acme.BookStore.Web/Acme.BookStore.Web.csproj +++ b/samples/BookStore/src/Acme.BookStore.Web/Acme.BookStore.Web.csproj @@ -4,6 +4,7 @@ netcoreapp2.2 + InProcess $(AssetTargetFallback);portable-net45+win8+wp8+wpa81; true true diff --git a/samples/BookStore/src/Acme.BookStore.Web/Program.cs b/samples/BookStore/src/Acme.BookStore.Web/Program.cs index 0ed9fd6438..bef69a6bd0 100644 --- a/samples/BookStore/src/Acme.BookStore.Web/Program.cs +++ b/samples/BookStore/src/Acme.BookStore.Web/Program.cs @@ -43,6 +43,7 @@ namespace Acme.BookStore.Web .UseKestrel() .UseContentRoot(Directory.GetCurrentDirectory()) .UseIISIntegration() + .UseIIS() .UseStartup() .UseSerilog() .Build(); From 400ac441962e47cc823fc0cc881a8a72881fad66 Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Thu, 13 Jun 2019 08:43:44 +0300 Subject: [PATCH 5/5] added automapper config in microservice demo product management resolves https://github.com/abpframework/abp/issues/1273 --- .../ProductManagementApplicationAutoMapperProfile.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/MicroserviceDemo/modules/product/src/ProductManagement.Application/ProductManagement/ProductManagementApplicationAutoMapperProfile.cs b/samples/MicroserviceDemo/modules/product/src/ProductManagement.Application/ProductManagement/ProductManagementApplicationAutoMapperProfile.cs index e42b94e48c..dcdd9d7b1a 100644 --- a/samples/MicroserviceDemo/modules/product/src/ProductManagement.Application/ProductManagement/ProductManagementApplicationAutoMapperProfile.cs +++ b/samples/MicroserviceDemo/modules/product/src/ProductManagement.Application/ProductManagement/ProductManagementApplicationAutoMapperProfile.cs @@ -6,7 +6,7 @@ namespace ProductManagement { public ProductManagementApplicationAutoMapperProfile() { - + CreateMap(); } } } \ No newline at end of file