diff --git a/src/ApiGateways/Mobile.Bff.Shopping/aggregator/Services/OrderingService.cs b/src/ApiGateways/Mobile.Bff.Shopping/aggregator/Services/OrderingService.cs index d34a5338a..0e04c9c22 100644 --- a/src/ApiGateways/Mobile.Bff.Shopping/aggregator/Services/OrderingService.cs +++ b/src/ApiGateways/Mobile.Bff.Shopping/aggregator/Services/OrderingService.cs @@ -11,31 +11,24 @@ namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Services { public class OrderingService : IOrderingService { - private readonly HttpClient _httpClient; - private readonly UrlsConfig _urls; + private readonly OrderingGrpc.OrderingGrpcClient _orderingGrpcClient; private readonly ILogger _logger; - public OrderingService(HttpClient httpClient, IOptions config, ILogger logger) + public OrderingService(OrderingGrpc.OrderingGrpcClient orderingGrpcClient, ILogger logger) { - _httpClient = httpClient; - _urls = config.Value; + _orderingGrpcClient = orderingGrpcClient; _logger = logger; } public async Task GetOrderDraftAsync(BasketData basketData) { + _logger.LogDebug(" grpc client created, basketData={@basketData}", basketData); - return await GrpcCallerService.CallService(_urls.GrpcOrdering, async channel => - { - var client = new OrderingGrpc.OrderingGrpcClient(channel); - _logger.LogDebug(" grpc client created, basketData={@basketData}", basketData); - - var command = MapToOrderDraftCommand(basketData); - var response = await client.CreateOrderDraftFromBasketDataAsync(command); - _logger.LogDebug(" grpc response: {@response}", response); + var command = MapToOrderDraftCommand(basketData); + var response = await _orderingGrpcClient.CreateOrderDraftFromBasketDataAsync(command); + _logger.LogDebug(" grpc response: {@response}", response); - return MapToResponse(response, basketData); - }); + return MapToResponse(response, basketData); } private OrderData MapToResponse(GrpcOrdering.OrderDraftDTO orderDraft, BasketData basketData) diff --git a/src/ApiGateways/Mobile.Bff.Shopping/aggregator/Startup.cs b/src/ApiGateways/Mobile.Bff.Shopping/aggregator/Startup.cs index 812163d29..ea06d866c 100644 --- a/src/ApiGateways/Mobile.Bff.Shopping/aggregator/Startup.cs +++ b/src/ApiGateways/Mobile.Bff.Shopping/aggregator/Startup.cs @@ -1,5 +1,6 @@ using Devspaces.Support; using GrpcBasket; +using GrpcOrdering; using HealthChecks.UI.Client; using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.AspNetCore.Builder; @@ -205,6 +206,12 @@ namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator options.Address = new Uri(basketApi); }).AddInterceptor(); + services.AddGrpcClient((services, options) => + { + var orderingApi = services.GetRequiredService>().Value.GrpcOrdering; + options.Address = new Uri(orderingApi); + }).AddInterceptor(); + return services; } diff --git a/src/ApiGateways/Web.Bff.Shopping/aggregator/Services/OrderingService.cs b/src/ApiGateways/Web.Bff.Shopping/aggregator/Services/OrderingService.cs index b460f4864..5ab8045c2 100644 --- a/src/ApiGateways/Web.Bff.Shopping/aggregator/Services/OrderingService.cs +++ b/src/ApiGateways/Web.Bff.Shopping/aggregator/Services/OrderingService.cs @@ -1,6 +1,6 @@ using GrpcOrdering; -using Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Config; using Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Models; +using Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using System.Linq; @@ -11,30 +11,24 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services { public class OrderingService : IOrderingService { - private readonly UrlsConfig _urls; + private readonly OrderingGrpc.OrderingGrpcClient _orderingGrpcClient; private readonly ILogger _logger; - public readonly HttpClient _httpClient; - public OrderingService(HttpClient httpClient, IOptions config, ILogger logger) + public OrderingService(OrderingGrpc.OrderingGrpcClient orderingGrpcClient, ILogger logger) { - _urls = config.Value; - _httpClient = httpClient; + _orderingGrpcClient = orderingGrpcClient; _logger = logger; } public async Task GetOrderDraftAsync(BasketData basketData) { - return await GrpcCallerService.CallService(_urls.GrpcOrdering, async channel => - { - var client = new OrderingGrpc.OrderingGrpcClient(channel); - _logger.LogDebug(" grpc client created, basketData={@basketData}", basketData); + _logger.LogDebug(" grpc client created, basketData={@basketData}", basketData); - var command = MapToOrderDraftCommand(basketData); - var response = await client.CreateOrderDraftFromBasketDataAsync(command); - _logger.LogDebug(" grpc response: {@response}", response); + var command = MapToOrderDraftCommand(basketData); + var response = await _orderingGrpcClient.CreateOrderDraftFromBasketDataAsync(command); + _logger.LogDebug(" grpc response: {@response}", response); - return MapToResponse(response, basketData); - }); + return MapToResponse(response, basketData); } private OrderData MapToResponse(GrpcOrdering.OrderDraftDTO orderDraft, BasketData basketData) diff --git a/src/ApiGateways/Web.Bff.Shopping/aggregator/Startup.cs b/src/ApiGateways/Web.Bff.Shopping/aggregator/Startup.cs index 06af6901f..e3330b2d2 100644 --- a/src/ApiGateways/Web.Bff.Shopping/aggregator/Startup.cs +++ b/src/ApiGateways/Web.Bff.Shopping/aggregator/Startup.cs @@ -1,5 +1,6 @@ using Devspaces.Support; using GrpcBasket; +using GrpcOrdering; using HealthChecks.UI.Client; using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.AspNetCore.Builder; @@ -210,6 +211,12 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator options.Address = new Uri(basketApi); }).AddInterceptor(); + services.AddGrpcClient((services, options) => + { + var orderingApi = services.GetRequiredService>().Value.GrpcOrdering; + options.Address = new Uri(orderingApi); + }).AddInterceptor(); + return services; } }