diff --git a/src/ApiGateways/Mobile.Bff.Shopping/aggregator/Infrastructure/Http2SupportGrpcInterceptor.cs b/src/ApiGateways/Mobile.Bff.Shopping/aggregator/Infrastructure/GrpcExceptionInterceptor.cs similarity index 52% rename from src/ApiGateways/Mobile.Bff.Shopping/aggregator/Infrastructure/Http2SupportGrpcInterceptor.cs rename to src/ApiGateways/Mobile.Bff.Shopping/aggregator/Infrastructure/GrpcExceptionInterceptor.cs index b38178fc3..6dc0cfb1f 100644 --- a/src/ApiGateways/Mobile.Bff.Shopping/aggregator/Infrastructure/Http2SupportGrpcInterceptor.cs +++ b/src/ApiGateways/Mobile.Bff.Shopping/aggregator/Infrastructure/GrpcExceptionInterceptor.cs @@ -1,15 +1,14 @@ using Grpc.Core; using Grpc.Core.Interceptors; using Microsoft.Extensions.Logging; -using System; namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Infrastructure { - public class Http2SupportGrpcInterceptor : Interceptor + public class GrpcExceptionInterceptor : Interceptor { - private readonly ILogger _logger; + private readonly ILogger _logger; - public Http2SupportGrpcInterceptor(ILogger logger) + public GrpcExceptionInterceptor(ILogger logger) { _logger = logger; } @@ -19,10 +18,7 @@ namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Infrastruct ClientInterceptorContext context, AsyncUnaryCallContinuation continuation) { - AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true); - AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2Support", true); - - _logger.LogInformation("Calling via grpc client base address serviceName ={@ServiceName}, BaseAddress={@Host} ", context.Method.ServiceName, context.Host); + _logger.LogInformation("Calling via grpc client base address serviceName={@ServiceName}, BaseAddress={@Host}", context.Method.ServiceName, context.Host); try { @@ -33,11 +29,6 @@ namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Infrastruct _logger.LogError("Error calling via grpc: {Status} - {Message}", e.Status, e.Message); return default; } - finally - { - AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", false); - AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2Support", false); - } } } } diff --git a/src/ApiGateways/Mobile.Bff.Shopping/aggregator/Mobile.Shopping.HttpAggregator.csproj b/src/ApiGateways/Mobile.Bff.Shopping/aggregator/Mobile.Shopping.HttpAggregator.csproj index 770d084c3..09c238f9d 100644 --- a/src/ApiGateways/Mobile.Bff.Shopping/aggregator/Mobile.Shopping.HttpAggregator.csproj +++ b/src/ApiGateways/Mobile.Bff.Shopping/aggregator/Mobile.Shopping.HttpAggregator.csproj @@ -20,6 +20,7 @@ + diff --git a/src/ApiGateways/Mobile.Bff.Shopping/aggregator/Services/BasketService.cs b/src/ApiGateways/Mobile.Bff.Shopping/aggregator/Services/BasketService.cs index 5e97eed50..29f02e720 100644 --- a/src/ApiGateways/Mobile.Bff.Shopping/aggregator/Services/BasketService.cs +++ b/src/ApiGateways/Mobile.Bff.Shopping/aggregator/Services/BasketService.cs @@ -10,13 +10,11 @@ namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Services { public class BasketService : IBasketService { - private readonly UrlsConfig _urls; private readonly Basket.BasketClient _basketClient; private readonly ILogger _logger; - public BasketService(Basket.BasketClient basketClient, IOptions config, ILogger logger) + public BasketService(Basket.BasketClient basketClient, ILogger logger) { - _urls = config.Value; _basketClient = basketClient; _logger = logger; } diff --git a/src/ApiGateways/Mobile.Bff.Shopping/aggregator/Startup.cs b/src/ApiGateways/Mobile.Bff.Shopping/aggregator/Startup.cs index 8eb0a5788..812163d29 100644 --- a/src/ApiGateways/Mobile.Bff.Shopping/aggregator/Startup.cs +++ b/src/ApiGateways/Mobile.Bff.Shopping/aggregator/Startup.cs @@ -180,10 +180,6 @@ namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator services.AddSingleton(); //register http services - services - .AddHttpClient() - .AddHttpMessageHandler() - .AddDevspacesSupport(); services.AddHttpClient() .AddDevspacesSupport(); @@ -199,13 +195,15 @@ namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator public static IServiceCollection AddGrpcServices(this IServiceCollection services) { - services.AddSingleton(); + services.AddSingleton(); + + services.AddScoped(); services.AddGrpcClient((services, options) => { - var basketApi = services.GetService>().Value.Basket; + var basketApi = services.GetRequiredService>().Value.GrpcBasket; options.Address = new Uri(basketApi); - }).AddInterceptor(); + }).AddInterceptor(); return services; } diff --git a/src/ApiGateways/Web.Bff.Shopping/aggregator/Dockerfile b/src/ApiGateways/Web.Bff.Shopping/aggregator/Dockerfile index 037105cb4..c6e7b8be6 100644 --- a/src/ApiGateways/Web.Bff.Shopping/aggregator/Dockerfile +++ b/src/ApiGateways/Web.Bff.Shopping/aggregator/Dockerfile @@ -1,8 +1,8 @@ -FROM mcr.microsoft.com/dotnet/core/aspnet:3.1 AS base +FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base WORKDIR /app EXPOSE 80 -FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build +FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build WORKDIR /src # It's important to keep lines from here down to "COPY . ." identical in all Dockerfiles diff --git a/src/ApiGateways/Web.Bff.Shopping/aggregator/Infrastructure/GrpcExceptionInterceptor.cs b/src/ApiGateways/Web.Bff.Shopping/aggregator/Infrastructure/GrpcExceptionInterceptor.cs new file mode 100644 index 000000000..2bbe69cf5 --- /dev/null +++ b/src/ApiGateways/Web.Bff.Shopping/aggregator/Infrastructure/GrpcExceptionInterceptor.cs @@ -0,0 +1,32 @@ +using Grpc.Core; +using Grpc.Core.Interceptors; +using Microsoft.Extensions.Logging; + +namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Infrastructure +{ + public class GrpcExceptionInterceptor : Interceptor + { + private readonly ILogger _logger; + + public GrpcExceptionInterceptor(ILogger logger) + { + _logger = logger; + } + + public override AsyncUnaryCall AsyncUnaryCall( + TRequest request, + ClientInterceptorContext context, + AsyncUnaryCallContinuation continuation) + { + try + { + return continuation(request, context); + } + catch (RpcException e) + { + _logger.LogError("Error calling via grpc: {Status} - {Message}", e.Status, e.Message); + return default; + } + } + } +} diff --git a/src/ApiGateways/Web.Bff.Shopping/aggregator/Infrastructure/Http2SupportGrpcInterceptor.cs b/src/ApiGateways/Web.Bff.Shopping/aggregator/Infrastructure/Http2SupportGrpcInterceptor.cs deleted file mode 100644 index 522a0ad65..000000000 --- a/src/ApiGateways/Web.Bff.Shopping/aggregator/Infrastructure/Http2SupportGrpcInterceptor.cs +++ /dev/null @@ -1,43 +0,0 @@ -using Grpc.Core; -using Grpc.Core.Interceptors; -using Microsoft.Extensions.Logging; -using System; - -namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Infrastructure -{ - public class Http2SupportGrpcInterceptor : Interceptor - { - private readonly ILogger _logger; - - public Http2SupportGrpcInterceptor(ILogger logger) - { - _logger = logger; - } - - public override AsyncUnaryCall AsyncUnaryCall( - TRequest request, - ClientInterceptorContext context, - AsyncUnaryCallContinuation continuation) - { - AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true); - AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2Support", true); - - _logger.LogInformation("Calling via grpc client base address serviceName ={@ServiceName}, BaseAddress={@Host} ", context.Method.ServiceName, context.Host); - - try - { - return continuation(request, context); - } - catch (RpcException e) - { - _logger.LogError("Error calling via grpc: {Status} - {Message}", e.Status, e.Message); - return default; - } - finally - { - AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", false); - AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2Support", false); - } - } - } -} diff --git a/src/ApiGateways/Web.Bff.Shopping/aggregator/Services/BasketService.cs b/src/ApiGateways/Web.Bff.Shopping/aggregator/Services/BasketService.cs index 858251b25..7b526a5b9 100644 --- a/src/ApiGateways/Web.Bff.Shopping/aggregator/Services/BasketService.cs +++ b/src/ApiGateways/Web.Bff.Shopping/aggregator/Services/BasketService.cs @@ -10,13 +10,11 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services { public class BasketService : IBasketService { - private readonly UrlsConfig _urls; private readonly Basket.BasketClient _basketClient; private readonly ILogger _logger; - public BasketService(Basket.BasketClient basketClient, IOptions config, ILogger logger) + public BasketService(Basket.BasketClient basketClient, ILogger logger) { - _urls = config.Value; _basketClient = basketClient; _logger = logger; } diff --git a/src/ApiGateways/Web.Bff.Shopping/aggregator/Startup.cs b/src/ApiGateways/Web.Bff.Shopping/aggregator/Startup.cs index 48b153370..06af6901f 100644 --- a/src/ApiGateways/Web.Bff.Shopping/aggregator/Startup.cs +++ b/src/ApiGateways/Web.Bff.Shopping/aggregator/Startup.cs @@ -44,7 +44,7 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator .AddUrlGroup(new Uri(Configuration["MarketingUrlHC"]), name: "marketingapi-check", tags: new string[] { "marketingapi" }) .AddUrlGroup(new Uri(Configuration["PaymentUrlHC"]), name: "paymentapi-check", tags: new string[] { "paymentapi" }) .AddUrlGroup(new Uri(Configuration["LocationUrlHC"]), name: "locationapi-check", tags: new string[] { "locationapi" }); - + services.AddCustomMvc(Configuration) .AddCustomAuthentication(Configuration) .AddDevspaces() @@ -142,7 +142,7 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator Version = "v1", Description = "Shopping Aggregator for Web Clients" }); - + options.AddSecurityDefinition("oauth2", new OpenApiSecurityScheme { Type = SecuritySchemeType.OAuth2, @@ -184,10 +184,6 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator //register http services - services.AddHttpClient() - .AddHttpMessageHandler() - .AddDevspacesSupport(); - services.AddHttpClient() .AddDevspacesSupport(); @@ -204,13 +200,15 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator public static IServiceCollection AddGrpcServices(this IServiceCollection services) { - services.AddSingleton(); + services.AddSingleton(); + + services.AddScoped(); services.AddGrpcClient((services, options) => { - var basketApi = services.GetService>().Value.Basket; + var basketApi = services.GetRequiredService>().Value.GrpcBasket; options.Address = new Uri(basketApi); - }).AddInterceptor(); + }).AddInterceptor(); return services; } diff --git a/src/ApiGateways/Web.Bff.Shopping/aggregator/Web.Shopping.HttpAggregator.csproj b/src/ApiGateways/Web.Bff.Shopping/aggregator/Web.Shopping.HttpAggregator.csproj index 2cef24f4e..8258a8c16 100644 --- a/src/ApiGateways/Web.Bff.Shopping/aggregator/Web.Shopping.HttpAggregator.csproj +++ b/src/ApiGateways/Web.Bff.Shopping/aggregator/Web.Shopping.HttpAggregator.csproj @@ -1,7 +1,7 @@  - netcoreapp3.1 + net5.0 Web.Shopping.HttpAggregator Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator ..\..\..\docker-compose.dcproj @@ -15,20 +15,21 @@ - - - - - - - - + + + + + + + + + - - - + + + - + diff --git a/src/Services/Basket/Basket.API/Basket.API.csproj b/src/Services/Basket/Basket.API/Basket.API.csproj index 4ec4811e5..4921041f2 100644 --- a/src/Services/Basket/Basket.API/Basket.API.csproj +++ b/src/Services/Basket/Basket.API/Basket.API.csproj @@ -16,30 +16,30 @@ - - - - - - - - - - - + + + + + + + + + + + - - - - + + + + - + - + diff --git a/src/Services/Basket/Basket.FunctionalTests/Basket.FunctionalTests.csproj b/src/Services/Basket/Basket.FunctionalTests/Basket.FunctionalTests.csproj index ed6c9214e..9da204e5f 100644 --- a/src/Services/Basket/Basket.FunctionalTests/Basket.FunctionalTests.csproj +++ b/src/Services/Basket/Basket.FunctionalTests/Basket.FunctionalTests.csproj @@ -16,11 +16,11 @@ - - - - - + + + + + all runtime; build; native; contentfiles; analyzers