From 02e76034b638e781c53404dd8d91b8c0fb647d22 Mon Sep 17 00:00:00 2001 From: Galip Tolga Erdem Date: Sat, 29 Jan 2022 04:22:24 +0300 Subject: [PATCH 01/10] added public product grpc service --- .../CatalogServiceHttpApiHostModule.cs | 26 ++++++++++++++++++- ...opOnAbp.CatalogService.HttpApi.Host.csproj | 12 +++++++++ .../Grpc/PublicProductGrpService.cs | 26 +++++++++++++++++++ .../Protos/product.proto | 21 +++++++++++++++ .../ApplicationBuilderHelper.cs | 9 +++++++ 5 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/Grpc/PublicProductGrpService.cs create mode 100644 services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/Protos/product.proto diff --git a/services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/CatalogServiceHttpApiHostModule.cs b/services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/CatalogServiceHttpApiHostModule.cs index 2b0a897b..8114462b 100644 --- a/services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/CatalogServiceHttpApiHostModule.cs +++ b/services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/CatalogServiceHttpApiHostModule.cs @@ -7,9 +7,12 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Threading.Tasks; +using EShopOnAbp.CatalogService.Grpc; using EShopOnAbp.CatalogService.MongoDB; +using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Configuration; using Volo.Abp; using Volo.Abp.AspNetCore.Mvc; @@ -80,6 +83,10 @@ public class CatalogServiceHttpApiHostModule : AbpModule }); Configure(options => { options.AutoValidate = false; }); + context.Services.AddGrpc(options => + { + options.EnableDetailedErrors = true; + }); } public override void OnApplicationInitialization(ApplicationInitializationContext context) @@ -111,7 +118,24 @@ public class CatalogServiceHttpApiHostModule : AbpModule app.UseAbpSerilogEnrichers(); app.UseAuditing(); app.UseUnitOfWork(); - app.UseConfiguredEndpoints(); + app.UseConfiguredEndpoints(endpoints => + { + endpoints.MapGrpcService(); + endpoints.MapGet("/_proto/", async ctx => + { + ctx.Response.ContentType = "text/plain"; + using var fs = new FileStream(Path.Combine(env.ContentRootPath, "Protos", "product.proto"), FileMode.Open, FileAccess.Read); + using var sr = new StreamReader(fs); + while (!sr.EndOfStream) + { + var line = await sr.ReadLineAsync(); + if (line != "/* >>" || line != "<< */") + { + await ctx.Response.WriteAsync(line); + } + } + }); + }); } public override async Task OnPostApplicationInitializationAsync(ApplicationInitializationContext context) diff --git a/services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/EShopOnAbp.CatalogService.HttpApi.Host.csproj b/services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/EShopOnAbp.CatalogService.HttpApi.Host.csproj index b7e561d5..878bd706 100644 --- a/services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/EShopOnAbp.CatalogService.HttpApi.Host.csproj +++ b/services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/EShopOnAbp.CatalogService.HttpApi.Host.csproj @@ -18,6 +18,18 @@ + + + + + + + + + + + + diff --git a/services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/Grpc/PublicProductGrpService.cs b/services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/Grpc/PublicProductGrpService.cs new file mode 100644 index 00000000..e0872370 --- /dev/null +++ b/services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/Grpc/PublicProductGrpService.cs @@ -0,0 +1,26 @@ +using System; +using System.Threading.Tasks; +using EShopOnAbp.CatalogService.Products; +using Grpc.Core; +using Volo.Abp.Domain.Repositories; +using Volo.Abp.ObjectMapping; + +namespace EShopOnAbp.CatalogService.Grpc; + +public class PublicProductGrpService : ProductPublic.ProductPublicBase +{ + private readonly IRepository _productRepository; + private readonly IObjectMapper _objectMapper; + + public PublicProductGrpService(IRepository productRepository, IObjectMapper objectMapper) + { + _productRepository = productRepository; + _objectMapper = objectMapper; + } + + public override async Task GetAsync(ProductRequest request, ServerCallContext context) + { + var product = await _productRepository.GetAsync(Guid.Parse(request.Id)); + return _objectMapper.Map(product); + } +} \ No newline at end of file diff --git a/services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/Protos/product.proto b/services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/Protos/product.proto new file mode 100644 index 00000000..b096bd65 --- /dev/null +++ b/services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/Protos/product.proto @@ -0,0 +1,21 @@ +syntax = "proto3"; + +option csharp_namespace = "EShopOnAbp.CatalogService.Grpc"; + +package CatalogApi; + +service ProductPublic { + rpc GetAsync(ProductRequest) returns (ProductDto) {} +} + +message ProductRequest { + string id = 1; +} + +message ProductDto { + string id = 1; + string code = 2; + string name = 3; + float price = 4; + int32 stockCount = 5; +} diff --git a/shared/EShopOnAbp.Shared.Hosting.AspNetCore/ApplicationBuilderHelper.cs b/shared/EShopOnAbp.Shared.Hosting.AspNetCore/ApplicationBuilderHelper.cs index 90faea26..25cdd1f4 100644 --- a/shared/EShopOnAbp.Shared.Hosting.AspNetCore/ApplicationBuilderHelper.cs +++ b/shared/EShopOnAbp.Shared.Hosting.AspNetCore/ApplicationBuilderHelper.cs @@ -1,5 +1,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Serilog; @@ -13,6 +15,13 @@ public static class ApplicationBuilderHelper where TStartupModule : IAbpModule { var builder = WebApplication.CreateBuilder(args); + builder.WebHost.ConfigureKestrel(serverOptions => + { + serverOptions.ConfigureEndpointDefaults(listenOptions => + { + listenOptions.Protocols = HttpProtocols.Http1AndHttp2; + }); + }); builder.Host .AddAppSettingsSecretsJson() .UseAutofac() From 55d5d6dc1f8f4d3372c031fbd3e796e3d1f5a96e Mon Sep 17 00:00:00 2001 From: Galip Tolga Erdem Date: Sat, 29 Jan 2022 05:22:53 +0300 Subject: [PATCH 02/10] added basket client --- .../BasketServiceHttpApiHostModule.cs | 9 ++++ .../Configs/UrlsConfig.cs | 7 +++ ...hopOnAbp.BasketService.HttpApi.Host.csproj | 13 +++++ .../appsettings.Development.json | 4 ++ .../Program.cs | 47 ++++++++++++++++++- .../Protos/product.proto | 12 ++++- 6 files changed, 89 insertions(+), 3 deletions(-) create mode 100644 services/basket/src/EShopOnAbp.BasketService.HttpApi.Host/Configs/UrlsConfig.cs diff --git a/services/basket/src/EShopOnAbp.BasketService.HttpApi.Host/BasketServiceHttpApiHostModule.cs b/services/basket/src/EShopOnAbp.BasketService.HttpApi.Host/BasketServiceHttpApiHostModule.cs index a1d990d5..7cd9f621 100644 --- a/services/basket/src/EShopOnAbp.BasketService.HttpApi.Host/BasketServiceHttpApiHostModule.cs +++ b/services/basket/src/EShopOnAbp.BasketService.HttpApi.Host/BasketServiceHttpApiHostModule.cs @@ -7,7 +7,10 @@ using Microsoft.Extensions.Hosting; using System; using System.Collections.Generic; using System.Linq; +using EShopOnAbp.BasketService.Configs; +using EShopOnAbp.CatalogService.Grpc; using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Options; using Volo.Abp; using Volo.Abp.AspNetCore.Mvc; using Volo.Abp.AspNetCore.Mvc.AntiForgery; @@ -72,6 +75,12 @@ public class BasketServiceHttpApiHostModule : AbpModule }); Configure(options => { options.AutoValidate = false; }); + + context.Services.AddGrpcClient((services, options) => + { + var catalogApi = services.GetRequiredService>().Value.GrpcCatalog; + options.Address = new Uri(catalogApi); + }); } public override void OnApplicationInitialization(ApplicationInitializationContext context) diff --git a/services/basket/src/EShopOnAbp.BasketService.HttpApi.Host/Configs/UrlsConfig.cs b/services/basket/src/EShopOnAbp.BasketService.HttpApi.Host/Configs/UrlsConfig.cs new file mode 100644 index 00000000..d45a3b3e --- /dev/null +++ b/services/basket/src/EShopOnAbp.BasketService.HttpApi.Host/Configs/UrlsConfig.cs @@ -0,0 +1,7 @@ +namespace EShopOnAbp.BasketService.Configs; + +public class UrlsConfig +{ + public string Catalog { get; set; } + public string GrpcCatalog { get; set; } +} \ No newline at end of file diff --git a/services/basket/src/EShopOnAbp.BasketService.HttpApi.Host/EShopOnAbp.BasketService.HttpApi.Host.csproj b/services/basket/src/EShopOnAbp.BasketService.HttpApi.Host/EShopOnAbp.BasketService.HttpApi.Host.csproj index baba3357..1e6e79bb 100644 --- a/services/basket/src/EShopOnAbp.BasketService.HttpApi.Host/EShopOnAbp.BasketService.HttpApi.Host.csproj +++ b/services/basket/src/EShopOnAbp.BasketService.HttpApi.Host/EShopOnAbp.BasketService.HttpApi.Host.csproj @@ -17,6 +17,15 @@ + + + + + + + + + @@ -25,4 +34,8 @@ + + + + diff --git a/services/basket/src/EShopOnAbp.BasketService.HttpApi.Host/appsettings.Development.json b/services/basket/src/EShopOnAbp.BasketService.HttpApi.Host/appsettings.Development.json index 2c63c085..4ea1f3f6 100644 --- a/services/basket/src/EShopOnAbp.BasketService.HttpApi.Host/appsettings.Development.json +++ b/services/basket/src/EShopOnAbp.BasketService.HttpApi.Host/appsettings.Development.json @@ -1,2 +1,6 @@ { + "urls": { + "catalog": "https://localhost:44354", + "grpcCatalog": "http://localhost:81" + } } diff --git a/services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/Program.cs b/services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/Program.cs index 74728f1c..2a50da33 100644 --- a/services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/Program.cs +++ b/services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/Program.cs @@ -2,6 +2,10 @@ using System.Threading.Tasks; using EShopOnAbp.Shared.Hosting.AspNetCore; using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Server.Kestrel.Core; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; using Serilog; namespace EShopOnAbp.CatalogService; @@ -17,8 +21,31 @@ public class Program try { Log.Information($"Starting {assemblyName}."); - var app = await ApplicationBuilderHelper - .BuildApplicationAsync(args); + // var app = await ApplicationBuilderHelper + // .BuildApplicationAsync(args); + + var builder = WebApplication.CreateBuilder(args); + builder.WebHost.ConfigureKestrel(serverOptions => + { + serverOptions.ConfigureEndpointDefaults(listenOptions => + { + listenOptions.Protocols = HttpProtocols.Http1AndHttp2; + }); + serverOptions.ListenLocalhost(44354, opts => + { + opts.UseHttps(); + opts.Protocols = HttpProtocols.Http1AndHttp2; + }); + serverOptions.ListenLocalhost(81, opts => { opts.Protocols = HttpProtocols.Http2; }); + }); + builder.Host + .AddAppSettingsSecretsJson() + .UseAutofac() + .UseSerilog(); + + await builder.AddApplicationAsync(); + var app = builder.Build(); + await app.InitializeApplicationAsync(); await app.RunAsync(); @@ -34,4 +61,20 @@ public class Program Log.CloseAndFlush(); } } + + // static (int httpPort, int grpcPort) GetDefinedPorts(IConfiguration config) + // { + // var grpcPort = config.GetValue("GRPC_PORT", 81); + // var port = config.GetValue("PORT", 80); + // return (port, grpcPort); + // } + // + // static IConfiguration GetConfiguration() + // { + // return new ConfigurationBuilder() + // .SetBasePath(Directory.GetCurrentDirectory()) + // .AddJsonFile("appsettings.json") + // .AddEnvironmentVariables() + // .Build(); + // } } \ No newline at end of file diff --git a/services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/Protos/product.proto b/services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/Protos/product.proto index b096bd65..97588fca 100644 --- a/services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/Protos/product.proto +++ b/services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/Protos/product.proto @@ -1,11 +1,21 @@ syntax = "proto3"; +/* >> +import "google/api/annotations.proto"; +<< */ + option csharp_namespace = "EShopOnAbp.CatalogService.Grpc"; package CatalogApi; service ProductPublic { - rpc GetAsync(ProductRequest) returns (ProductDto) {} + rpc GetAsync(ProductRequest) returns (ProductDto) { + /* >> + option (google.api.http) = { + get: "/api/catalog/product/{id}" + }; +<< */ + } } message ProductRequest { From e29792e00b730dffe2c6f5009e8e0c4491a5dfb2 Mon Sep 17 00:00:00 2001 From: Galip Tolga Erdem Date: Sat, 29 Jan 2022 06:43:51 +0300 Subject: [PATCH 03/10] Moved client and server to respected layers --- .../BasketProductService.cs | 24 +++++++---- ...sketServiceApplicationAutoMapperProfile.cs | 2 + .../BasketServiceApplicationModule.cs | 18 +++++++- .../Configs/UrlsConfig.cs | 0 ...ShopOnAbp.BasketService.Application.csproj | 13 ++++++ .../Grpc/GrpcExceptionInterceptor.cs | 42 +++++++++++++++++++ .../BasketServiceHttpApiHostModule.cs | 9 ---- ...hopOnAbp.BasketService.HttpApi.Host.csproj | 13 ------ ...atalogService.Application.Contracts.csproj | 12 ++++++ .../Protos/product.proto | 9 ++-- ...alogServiceApplicationAutoMapperProfile.cs | 2 + .../Grpc/PublicProductGrpService.cs | 4 +- .../CatalogServiceHttpApiHostModule.cs | 14 ------- ...opOnAbp.CatalogService.HttpApi.Host.csproj | 8 ---- .../Program.cs | 3 +- 15 files changed, 111 insertions(+), 62 deletions(-) rename services/basket/src/{EShopOnAbp.BasketService.HttpApi.Host => EShopOnAbp.BasketService.Application}/Configs/UrlsConfig.cs (100%) create mode 100644 services/basket/src/EShopOnAbp.BasketService.Application/Grpc/GrpcExceptionInterceptor.cs rename services/catalog/src/{EShopOnAbp.CatalogService.HttpApi.Host => EShopOnAbp.CatalogService.Application.Contracts}/Protos/product.proto (71%) rename services/catalog/src/{EShopOnAbp.CatalogService.HttpApi.Host => EShopOnAbp.CatalogService.Application}/Grpc/PublicProductGrpService.cs (80%) diff --git a/services/basket/src/EShopOnAbp.BasketService.Application/BasketProductService.cs b/services/basket/src/EShopOnAbp.BasketService.Application/BasketProductService.cs index 176f039b..49a41854 100644 --- a/services/basket/src/EShopOnAbp.BasketService.Application/BasketProductService.cs +++ b/services/basket/src/EShopOnAbp.BasketService.Application/BasketProductService.cs @@ -1,25 +1,27 @@ using System; using System.Threading.Tasks; +using EShopOnAbp.CatalogService.Grpc; using EShopOnAbp.CatalogService.Products; +using Microsoft.Extensions.Logging; using Volo.Abp; using Volo.Abp.Caching; -using Volo.Abp.DependencyInjection; namespace EShopOnAbp.BasketService; -public class BasketProductService : IBasketProductService, ITransientDependency +public class BasketProductService : BasketServiceAppService, IBasketProductService { - private readonly IPublicProductAppService _productAppService; private readonly IDistributedCache _cache; + private readonly ProductPublic.ProductPublicClient _productPublicGrpcClient; public BasketProductService( - IPublicProductAppService productAppService, - IDistributedCache cache) + IDistributedCache cache, + ProductPublic.ProductPublicClient productPublicGrpcClient + ) { - _productAppService = productAppService; _cache = cache; + _productPublicGrpcClient = productPublicGrpcClient; } - + public async Task GetAsync(Guid productId) { return await _cache.GetOrAddAsync( @@ -28,9 +30,13 @@ public class BasketProductService : IBasketProductService, ITransientDependency ); } - private Task GetProductAsync(Guid productId) + private async Task GetProductAsync(Guid productId) { - return _productAppService.GetAsync(productId) ?? + var request = new ProductRequest { Id = productId.ToString() }; + Logger.LogInformation("=== GRPC request {@request}", request); + var response = await _productPublicGrpcClient.GetByIdAsync(request); + Logger.LogInformation("=== GRPC response {@response}", response); + return ObjectMapper.Map(response) ?? throw new UserFriendlyException(BasketServiceDomainErrorCodes.ProductNotFound); } } \ No newline at end of file diff --git a/services/basket/src/EShopOnAbp.BasketService.Application/BasketServiceApplicationAutoMapperProfile.cs b/services/basket/src/EShopOnAbp.BasketService.Application/BasketServiceApplicationAutoMapperProfile.cs index 7d781826..781a2073 100644 --- a/services/basket/src/EShopOnAbp.BasketService.Application/BasketServiceApplicationAutoMapperProfile.cs +++ b/services/basket/src/EShopOnAbp.BasketService.Application/BasketServiceApplicationAutoMapperProfile.cs @@ -1,4 +1,5 @@ using AutoMapper; +using EShopOnAbp.CatalogService.Grpc; using EShopOnAbp.CatalogService.Products; namespace EShopOnAbp.BasketService @@ -8,6 +9,7 @@ namespace EShopOnAbp.BasketService public BasketServiceApplicationAutoMapperProfile() { CreateMap(); + CreateMap(); } } } diff --git a/services/basket/src/EShopOnAbp.BasketService.Application/BasketServiceApplicationModule.cs b/services/basket/src/EShopOnAbp.BasketService.Application/BasketServiceApplicationModule.cs index 72eda9ce..1d3f7cdc 100644 --- a/services/basket/src/EShopOnAbp.BasketService.Application/BasketServiceApplicationModule.cs +++ b/services/basket/src/EShopOnAbp.BasketService.Application/BasketServiceApplicationModule.cs @@ -1,4 +1,10 @@ -using EShopOnAbp.CatalogService; +using System; +using EShopOnAbp.BasketService.Configs; +using EShopOnAbp.BasketService.Grpc; +using EShopOnAbp.CatalogService; +using EShopOnAbp.CatalogService.Grpc; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Options; using Volo.Abp.Application; using Volo.Abp.AutoMapper; using Volo.Abp.Modularity; @@ -16,10 +22,20 @@ namespace EShopOnAbp.BasketService { public override void ConfigureServices(ServiceConfigurationContext context) { + var configuration = context.Services.GetConfiguration(); + context.Services.AddOptions(); + context.Services.Configure(configuration.GetSection("urls")); + Configure(options => { options.AddMaps(); }); + + context.Services.AddGrpcClient((services, options) => + { + var catalogApi = services.GetRequiredService>().Value.GrpcCatalog; + options.Address = new Uri(catalogApi); + }).AddInterceptor(); } } } diff --git a/services/basket/src/EShopOnAbp.BasketService.HttpApi.Host/Configs/UrlsConfig.cs b/services/basket/src/EShopOnAbp.BasketService.Application/Configs/UrlsConfig.cs similarity index 100% rename from services/basket/src/EShopOnAbp.BasketService.HttpApi.Host/Configs/UrlsConfig.cs rename to services/basket/src/EShopOnAbp.BasketService.Application/Configs/UrlsConfig.cs diff --git a/services/basket/src/EShopOnAbp.BasketService.Application/EShopOnAbp.BasketService.Application.csproj b/services/basket/src/EShopOnAbp.BasketService.Application/EShopOnAbp.BasketService.Application.csproj index abe34e89..699af38c 100644 --- a/services/basket/src/EShopOnAbp.BasketService.Application/EShopOnAbp.BasketService.Application.csproj +++ b/services/basket/src/EShopOnAbp.BasketService.Application/EShopOnAbp.BasketService.Application.csproj @@ -18,4 +18,17 @@ + + + + + + + + + + + + + diff --git a/services/basket/src/EShopOnAbp.BasketService.Application/Grpc/GrpcExceptionInterceptor.cs b/services/basket/src/EShopOnAbp.BasketService.Application/Grpc/GrpcExceptionInterceptor.cs new file mode 100644 index 00000000..5c746202 --- /dev/null +++ b/services/basket/src/EShopOnAbp.BasketService.Application/Grpc/GrpcExceptionInterceptor.cs @@ -0,0 +1,42 @@ +using System.Threading.Tasks; +using Grpc.Core; +using Grpc.Core.Interceptors; +using Microsoft.Extensions.Logging; +using Volo.Abp.DependencyInjection; + +namespace EShopOnAbp.BasketService.Grpc; + +public class GrpcExceptionInterceptor : Interceptor, ITransientDependency +{ + private readonly ILogger _logger; + + public GrpcExceptionInterceptor(ILogger logger) + { + _logger = logger; + } + + public override AsyncUnaryCall AsyncUnaryCall( + TRequest request, + ClientInterceptorContext context, + AsyncUnaryCallContinuation continuation) + { + var call = continuation(request, context); + + return new AsyncUnaryCall(HandleResponse(call.ResponseAsync), call.ResponseHeadersAsync, + call.GetStatus, call.GetTrailers, call.Dispose); + } + + private async Task HandleResponse(Task task) + { + try + { + var response = await task; + return response; + } + catch (RpcException e) + { + _logger.LogError("Error calling via grpc: {Status} - {Message}", e.Status, e.Message); + return default; + } + } +} \ No newline at end of file diff --git a/services/basket/src/EShopOnAbp.BasketService.HttpApi.Host/BasketServiceHttpApiHostModule.cs b/services/basket/src/EShopOnAbp.BasketService.HttpApi.Host/BasketServiceHttpApiHostModule.cs index 7cd9f621..a1d990d5 100644 --- a/services/basket/src/EShopOnAbp.BasketService.HttpApi.Host/BasketServiceHttpApiHostModule.cs +++ b/services/basket/src/EShopOnAbp.BasketService.HttpApi.Host/BasketServiceHttpApiHostModule.cs @@ -7,10 +7,7 @@ using Microsoft.Extensions.Hosting; using System; using System.Collections.Generic; using System.Linq; -using EShopOnAbp.BasketService.Configs; -using EShopOnAbp.CatalogService.Grpc; using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.Options; using Volo.Abp; using Volo.Abp.AspNetCore.Mvc; using Volo.Abp.AspNetCore.Mvc.AntiForgery; @@ -75,12 +72,6 @@ public class BasketServiceHttpApiHostModule : AbpModule }); Configure(options => { options.AutoValidate = false; }); - - context.Services.AddGrpcClient((services, options) => - { - var catalogApi = services.GetRequiredService>().Value.GrpcCatalog; - options.Address = new Uri(catalogApi); - }); } public override void OnApplicationInitialization(ApplicationInitializationContext context) diff --git a/services/basket/src/EShopOnAbp.BasketService.HttpApi.Host/EShopOnAbp.BasketService.HttpApi.Host.csproj b/services/basket/src/EShopOnAbp.BasketService.HttpApi.Host/EShopOnAbp.BasketService.HttpApi.Host.csproj index 1e6e79bb..baba3357 100644 --- a/services/basket/src/EShopOnAbp.BasketService.HttpApi.Host/EShopOnAbp.BasketService.HttpApi.Host.csproj +++ b/services/basket/src/EShopOnAbp.BasketService.HttpApi.Host/EShopOnAbp.BasketService.HttpApi.Host.csproj @@ -17,15 +17,6 @@ - - - - - - - - - @@ -34,8 +25,4 @@ - - - - diff --git a/services/catalog/src/EShopOnAbp.CatalogService.Application.Contracts/EShopOnAbp.CatalogService.Application.Contracts.csproj b/services/catalog/src/EShopOnAbp.CatalogService.Application.Contracts/EShopOnAbp.CatalogService.Application.Contracts.csproj index 12e67a4c..e1b43742 100644 --- a/services/catalog/src/EShopOnAbp.CatalogService.Application.Contracts/EShopOnAbp.CatalogService.Application.Contracts.csproj +++ b/services/catalog/src/EShopOnAbp.CatalogService.Application.Contracts/EShopOnAbp.CatalogService.Application.Contracts.csproj @@ -16,4 +16,16 @@ + + + + + + + + + + + + diff --git a/services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/Protos/product.proto b/services/catalog/src/EShopOnAbp.CatalogService.Application.Contracts/Protos/product.proto similarity index 71% rename from services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/Protos/product.proto rename to services/catalog/src/EShopOnAbp.CatalogService.Application.Contracts/Protos/product.proto index 97588fca..fbf6afd2 100644 --- a/services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/Protos/product.proto +++ b/services/catalog/src/EShopOnAbp.CatalogService.Application.Contracts/Protos/product.proto @@ -9,7 +9,7 @@ option csharp_namespace = "EShopOnAbp.CatalogService.Grpc"; package CatalogApi; service ProductPublic { - rpc GetAsync(ProductRequest) returns (ProductDto) { + rpc GetById(ProductRequest) returns (ProductResponse) { /* >> option (google.api.http) = { get: "/api/catalog/product/{id}" @@ -22,10 +22,11 @@ message ProductRequest { string id = 1; } -message ProductDto { +message ProductResponse { string id = 1; string code = 2; string name = 3; - float price = 4; - int32 stockCount = 5; + string imageName = 4; + float price = 5; + int32 stockCount = 6; } diff --git a/services/catalog/src/EShopOnAbp.CatalogService.Application/CatalogServiceApplicationAutoMapperProfile.cs b/services/catalog/src/EShopOnAbp.CatalogService.Application/CatalogServiceApplicationAutoMapperProfile.cs index 5bd4edaf..899297aa 100644 --- a/services/catalog/src/EShopOnAbp.CatalogService.Application/CatalogServiceApplicationAutoMapperProfile.cs +++ b/services/catalog/src/EShopOnAbp.CatalogService.Application/CatalogServiceApplicationAutoMapperProfile.cs @@ -1,4 +1,5 @@ using AutoMapper; +using EShopOnAbp.CatalogService.Grpc; using EShopOnAbp.CatalogService.Products; namespace EShopOnAbp.CatalogService @@ -8,6 +9,7 @@ namespace EShopOnAbp.CatalogService public CatalogServiceApplicationAutoMapperProfile() { CreateMap(); + CreateMap(); } } } diff --git a/services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/Grpc/PublicProductGrpService.cs b/services/catalog/src/EShopOnAbp.CatalogService.Application/Grpc/PublicProductGrpService.cs similarity index 80% rename from services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/Grpc/PublicProductGrpService.cs rename to services/catalog/src/EShopOnAbp.CatalogService.Application/Grpc/PublicProductGrpService.cs index e0872370..ccd34229 100644 --- a/services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/Grpc/PublicProductGrpService.cs +++ b/services/catalog/src/EShopOnAbp.CatalogService.Application/Grpc/PublicProductGrpService.cs @@ -18,9 +18,9 @@ public class PublicProductGrpService : ProductPublic.ProductPublicBase _objectMapper = objectMapper; } - public override async Task GetAsync(ProductRequest request, ServerCallContext context) + public override async Task GetById(ProductRequest request, ServerCallContext context) { var product = await _productRepository.GetAsync(Guid.Parse(request.Id)); - return _objectMapper.Map(product); + return _objectMapper.Map(product); } } \ No newline at end of file diff --git a/services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/CatalogServiceHttpApiHostModule.cs b/services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/CatalogServiceHttpApiHostModule.cs index 8114462b..ae8547e6 100644 --- a/services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/CatalogServiceHttpApiHostModule.cs +++ b/services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/CatalogServiceHttpApiHostModule.cs @@ -121,20 +121,6 @@ public class CatalogServiceHttpApiHostModule : AbpModule app.UseConfiguredEndpoints(endpoints => { endpoints.MapGrpcService(); - endpoints.MapGet("/_proto/", async ctx => - { - ctx.Response.ContentType = "text/plain"; - using var fs = new FileStream(Path.Combine(env.ContentRootPath, "Protos", "product.proto"), FileMode.Open, FileAccess.Read); - using var sr = new StreamReader(fs); - while (!sr.EndOfStream) - { - var line = await sr.ReadLineAsync(); - if (line != "/* >>" || line != "<< */") - { - await ctx.Response.WriteAsync(line); - } - } - }); }); } diff --git a/services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/EShopOnAbp.CatalogService.HttpApi.Host.csproj b/services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/EShopOnAbp.CatalogService.HttpApi.Host.csproj index 878bd706..6a0af54a 100644 --- a/services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/EShopOnAbp.CatalogService.HttpApi.Host.csproj +++ b/services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/EShopOnAbp.CatalogService.HttpApi.Host.csproj @@ -20,15 +20,7 @@ - - - - - - - - diff --git a/services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/Program.cs b/services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/Program.cs index 2a50da33..38392d36 100644 --- a/services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/Program.cs +++ b/services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/Program.cs @@ -21,8 +21,6 @@ public class Program try { Log.Information($"Starting {assemblyName}."); - // var app = await ApplicationBuilderHelper - // .BuildApplicationAsync(args); var builder = WebApplication.CreateBuilder(args); builder.WebHost.ConfigureKestrel(serverOptions => @@ -36,6 +34,7 @@ public class Program opts.UseHttps(); opts.Protocols = HttpProtocols.Http1AndHttp2; }); + // Grpc port serverOptions.ListenLocalhost(81, opts => { opts.Protocols = HttpProtocols.Http2; }); }); builder.Host From ccb2e9548e368ded780633c97e6d7d4342f62c5c Mon Sep 17 00:00:00 2001 From: Galip Tolga Erdem Date: Sun, 30 Jan 2022 02:01:29 +0300 Subject: [PATCH 04/10] moved Kestrel configuration to appsettings --- .../Program.cs | 44 +------------------ .../appsettings.json | 12 +++++ .../ApplicationBuilderHelper.cs | 7 --- 3 files changed, 13 insertions(+), 50 deletions(-) diff --git a/services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/Program.cs b/services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/Program.cs index 38392d36..3ae318fc 100644 --- a/services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/Program.cs +++ b/services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/Program.cs @@ -2,10 +2,6 @@ using System.Threading.Tasks; using EShopOnAbp.Shared.Hosting.AspNetCore; using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Server.Kestrel.Core; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; using Serilog; namespace EShopOnAbp.CatalogService; @@ -22,29 +18,7 @@ public class Program { Log.Information($"Starting {assemblyName}."); - var builder = WebApplication.CreateBuilder(args); - builder.WebHost.ConfigureKestrel(serverOptions => - { - serverOptions.ConfigureEndpointDefaults(listenOptions => - { - listenOptions.Protocols = HttpProtocols.Http1AndHttp2; - }); - serverOptions.ListenLocalhost(44354, opts => - { - opts.UseHttps(); - opts.Protocols = HttpProtocols.Http1AndHttp2; - }); - // Grpc port - serverOptions.ListenLocalhost(81, opts => { opts.Protocols = HttpProtocols.Http2; }); - }); - builder.Host - .AddAppSettingsSecretsJson() - .UseAutofac() - .UseSerilog(); - - await builder.AddApplicationAsync(); - var app = builder.Build(); - + var app = await ApplicationBuilderHelper.BuildApplicationAsync(args); await app.InitializeApplicationAsync(); await app.RunAsync(); @@ -60,20 +34,4 @@ public class Program Log.CloseAndFlush(); } } - - // static (int httpPort, int grpcPort) GetDefinedPorts(IConfiguration config) - // { - // var grpcPort = config.GetValue("GRPC_PORT", 81); - // var port = config.GetValue("PORT", 80); - // return (port, grpcPort); - // } - // - // static IConfiguration GetConfiguration() - // { - // return new ConfigurationBuilder() - // .SetBasePath(Directory.GetCurrentDirectory()) - // .AddJsonFile("appsettings.json") - // .AddEnvironmentVariables() - // .Build(); - // } } \ No newline at end of file diff --git a/services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/appsettings.json b/services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/appsettings.json index 7b5799db..5d2eda53 100644 --- a/services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/appsettings.json +++ b/services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/appsettings.json @@ -40,5 +40,17 @@ }, "ElasticSearch": { "Url": "http://localhost:9200" + }, + "Kestrel": { + "Endpoints": { + "Http": { + "Url": "https://localhost:44354", + "Protocols": "Http1AndHttp2" + }, + "gRPC": { + "Url": "http://localhost:81", + "Protocols": "Http2" + } + } } } diff --git a/shared/EShopOnAbp.Shared.Hosting.AspNetCore/ApplicationBuilderHelper.cs b/shared/EShopOnAbp.Shared.Hosting.AspNetCore/ApplicationBuilderHelper.cs index 25cdd1f4..15a9bd5e 100644 --- a/shared/EShopOnAbp.Shared.Hosting.AspNetCore/ApplicationBuilderHelper.cs +++ b/shared/EShopOnAbp.Shared.Hosting.AspNetCore/ApplicationBuilderHelper.cs @@ -15,13 +15,6 @@ public static class ApplicationBuilderHelper where TStartupModule : IAbpModule { var builder = WebApplication.CreateBuilder(args); - builder.WebHost.ConfigureKestrel(serverOptions => - { - serverOptions.ConfigureEndpointDefaults(listenOptions => - { - listenOptions.Protocols = HttpProtocols.Http1AndHttp2; - }); - }); builder.Host .AddAppSettingsSecretsJson() .UseAutofac() From 9c7ad7411ab3323b0f9cc2d3bf6890aa06967d2f Mon Sep 17 00:00:00 2001 From: Galip Tolga Erdem Date: Mon, 31 Jan 2022 18:11:36 +0300 Subject: [PATCH 05/10] Removed custom urls and added GrpcUrl to Catalog remote service --- .../BasketServiceApplicationModule.cs | 19 +++++++++---------- .../Configs/UrlsConfig.cs | 7 ------- .../appsettings.Development.json | 4 ---- .../appsettings.json | 3 ++- 4 files changed, 11 insertions(+), 22 deletions(-) delete mode 100644 services/basket/src/EShopOnAbp.BasketService.Application/Configs/UrlsConfig.cs diff --git a/services/basket/src/EShopOnAbp.BasketService.Application/BasketServiceApplicationModule.cs b/services/basket/src/EShopOnAbp.BasketService.Application/BasketServiceApplicationModule.cs index 1d3f7cdc..2cf26502 100644 --- a/services/basket/src/EShopOnAbp.BasketService.Application/BasketServiceApplicationModule.cs +++ b/services/basket/src/EShopOnAbp.BasketService.Application/BasketServiceApplicationModule.cs @@ -1,12 +1,11 @@ using System; -using EShopOnAbp.BasketService.Configs; -using EShopOnAbp.BasketService.Grpc; +using System.Collections.Generic; using EShopOnAbp.CatalogService; using EShopOnAbp.CatalogService.Grpc; using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Options; using Volo.Abp.Application; using Volo.Abp.AutoMapper; +using Volo.Abp.Http.Client; using Volo.Abp.Modularity; namespace EShopOnAbp.BasketService @@ -23,19 +22,19 @@ namespace EShopOnAbp.BasketService public override void ConfigureServices(ServiceConfigurationContext context) { var configuration = context.Services.GetConfiguration(); - context.Services.AddOptions(); - context.Services.Configure(configuration.GetSection("urls")); - Configure(options => { options.AddMaps(); }); - + context.Services.AddGrpcClient((services, options) => { - var catalogApi = services.GetRequiredService>().Value.GrpcCatalog; - options.Address = new Uri(catalogApi); - }).AddInterceptor(); + var remoteServiceConfigurationProvider = services.GetRequiredService(); + var catalogServiceConfiguration = remoteServiceConfigurationProvider.GetConfigurationOrDefaultAsync("Catalog").Result; + var catalogGrpcUrl = catalogServiceConfiguration.GetOrDefault("GrpcUrl"); + + options.Address = new Uri(catalogGrpcUrl); + }); } } } diff --git a/services/basket/src/EShopOnAbp.BasketService.Application/Configs/UrlsConfig.cs b/services/basket/src/EShopOnAbp.BasketService.Application/Configs/UrlsConfig.cs deleted file mode 100644 index d45a3b3e..00000000 --- a/services/basket/src/EShopOnAbp.BasketService.Application/Configs/UrlsConfig.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace EShopOnAbp.BasketService.Configs; - -public class UrlsConfig -{ - public string Catalog { get; set; } - public string GrpcCatalog { get; set; } -} \ No newline at end of file diff --git a/services/basket/src/EShopOnAbp.BasketService.HttpApi.Host/appsettings.Development.json b/services/basket/src/EShopOnAbp.BasketService.HttpApi.Host/appsettings.Development.json index 4ea1f3f6..2c63c085 100644 --- a/services/basket/src/EShopOnAbp.BasketService.HttpApi.Host/appsettings.Development.json +++ b/services/basket/src/EShopOnAbp.BasketService.HttpApi.Host/appsettings.Development.json @@ -1,6 +1,2 @@ { - "urls": { - "catalog": "https://localhost:44354", - "grpcCatalog": "http://localhost:81" - } } diff --git a/services/basket/src/EShopOnAbp.BasketService.HttpApi.Host/appsettings.json b/services/basket/src/EShopOnAbp.BasketService.HttpApi.Host/appsettings.json index 2e9949c5..93adbecc 100644 --- a/services/basket/src/EShopOnAbp.BasketService.HttpApi.Host/appsettings.json +++ b/services/basket/src/EShopOnAbp.BasketService.HttpApi.Host/appsettings.json @@ -11,7 +11,8 @@ }, "RemoteServices": { "Catalog": { - "BaseUrl": "https://localhost:44354/" + "BaseUrl": "https://localhost:44354/", + "GrpcUrl": "http://localhost:81" } }, "Logging": { From f859fc80e5089ad29c4ee6929b4dbdfcb923ffb2 Mon Sep 17 00:00:00 2001 From: Galip Tolga Erdem Date: Mon, 31 Jan 2022 18:11:42 +0300 Subject: [PATCH 06/10] Delete GrpcExceptionInterceptor.cs --- .../Grpc/GrpcExceptionInterceptor.cs | 42 ------------------- 1 file changed, 42 deletions(-) delete mode 100644 services/basket/src/EShopOnAbp.BasketService.Application/Grpc/GrpcExceptionInterceptor.cs diff --git a/services/basket/src/EShopOnAbp.BasketService.Application/Grpc/GrpcExceptionInterceptor.cs b/services/basket/src/EShopOnAbp.BasketService.Application/Grpc/GrpcExceptionInterceptor.cs deleted file mode 100644 index 5c746202..00000000 --- a/services/basket/src/EShopOnAbp.BasketService.Application/Grpc/GrpcExceptionInterceptor.cs +++ /dev/null @@ -1,42 +0,0 @@ -using System.Threading.Tasks; -using Grpc.Core; -using Grpc.Core.Interceptors; -using Microsoft.Extensions.Logging; -using Volo.Abp.DependencyInjection; - -namespace EShopOnAbp.BasketService.Grpc; - -public class GrpcExceptionInterceptor : Interceptor, ITransientDependency -{ - private readonly ILogger _logger; - - public GrpcExceptionInterceptor(ILogger logger) - { - _logger = logger; - } - - public override AsyncUnaryCall AsyncUnaryCall( - TRequest request, - ClientInterceptorContext context, - AsyncUnaryCallContinuation continuation) - { - var call = continuation(request, context); - - return new AsyncUnaryCall(HandleResponse(call.ResponseAsync), call.ResponseHeadersAsync, - call.GetStatus, call.GetTrailers, call.Dispose); - } - - private async Task HandleResponse(Task task) - { - try - { - var response = await task; - return response; - } - catch (RpcException e) - { - _logger.LogError("Error calling via grpc: {Status} - {Message}", e.Status, e.Message); - return default; - } - } -} \ No newline at end of file From 9d0939a4f9c8bc1d2d823169acb1d9264442c4e0 Mon Sep 17 00:00:00 2001 From: Galip Tolga Erdem Date: Mon, 31 Jan 2022 18:36:07 +0300 Subject: [PATCH 07/10] removed unnecessary references --- .../EShopOnAbp.BasketService.Application.csproj | 3 --- 1 file changed, 3 deletions(-) diff --git a/services/basket/src/EShopOnAbp.BasketService.Application/EShopOnAbp.BasketService.Application.csproj b/services/basket/src/EShopOnAbp.BasketService.Application/EShopOnAbp.BasketService.Application.csproj index 699af38c..bbcbc805 100644 --- a/services/basket/src/EShopOnAbp.BasketService.Application/EShopOnAbp.BasketService.Application.csproj +++ b/services/basket/src/EShopOnAbp.BasketService.Application/EShopOnAbp.BasketService.Application.csproj @@ -20,9 +20,6 @@ - - - From a79d56fbbeab2ded069ca22818139933fb4fb2b4 Mon Sep 17 00:00:00 2001 From: Galip Tolga Erdem Date: Mon, 31 Jan 2022 18:51:10 +0300 Subject: [PATCH 08/10] Swapped to IOptionsMonitor instead of IRemoteServiceConfiguration --- .../BasketServiceApplicationModule.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/services/basket/src/EShopOnAbp.BasketService.Application/BasketServiceApplicationModule.cs b/services/basket/src/EShopOnAbp.BasketService.Application/BasketServiceApplicationModule.cs index 2cf26502..74a9e542 100644 --- a/services/basket/src/EShopOnAbp.BasketService.Application/BasketServiceApplicationModule.cs +++ b/services/basket/src/EShopOnAbp.BasketService.Application/BasketServiceApplicationModule.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using EShopOnAbp.CatalogService; using EShopOnAbp.CatalogService.Grpc; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Options; using Volo.Abp.Application; using Volo.Abp.AutoMapper; using Volo.Abp.Http.Client; @@ -27,10 +28,10 @@ namespace EShopOnAbp.BasketService options.AddMaps(); }); - context.Services.AddGrpcClient((services, options) => + context.Services.AddGrpcClient((services, options) => { - var remoteServiceConfigurationProvider = services.GetRequiredService(); - var catalogServiceConfiguration = remoteServiceConfigurationProvider.GetConfigurationOrDefaultAsync("Catalog").Result; + var remoteServiceOptions = services.GetRequiredService>().CurrentValue; + var catalogServiceConfiguration = remoteServiceOptions.RemoteServices.GetConfigurationOrDefault("Catalog"); var catalogGrpcUrl = catalogServiceConfiguration.GetOrDefault("GrpcUrl"); options.Address = new Uri(catalogGrpcUrl); From 42039c63b21d5e5dadc9bfd47889a6bf188ba1e4 Mon Sep 17 00:00:00 2001 From: Galip Tolga Erdem Date: Mon, 7 Feb 2022 10:00:10 +0300 Subject: [PATCH 09/10] BasketProduct service no longer inherits AppService --- .../BasketProductService.cs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/services/basket/src/EShopOnAbp.BasketService.Application/BasketProductService.cs b/services/basket/src/EShopOnAbp.BasketService.Application/BasketProductService.cs index 49a41854..a2d59306 100644 --- a/services/basket/src/EShopOnAbp.BasketService.Application/BasketProductService.cs +++ b/services/basket/src/EShopOnAbp.BasketService.Application/BasketProductService.cs @@ -4,21 +4,27 @@ using EShopOnAbp.CatalogService.Grpc; using EShopOnAbp.CatalogService.Products; using Microsoft.Extensions.Logging; using Volo.Abp; +using Volo.Abp.ObjectMapping; using Volo.Abp.Caching; namespace EShopOnAbp.BasketService; -public class BasketProductService : BasketServiceAppService, IBasketProductService +public class BasketProductService : IBasketProductService { private readonly IDistributedCache _cache; + private readonly ILogger _logger; + private readonly IObjectMapper _mapper; private readonly ProductPublic.ProductPublicClient _productPublicGrpcClient; public BasketProductService( IDistributedCache cache, - ProductPublic.ProductPublicClient productPublicGrpcClient - ) + ILogger logger, + IObjectMapper mapper, + ProductPublic.ProductPublicClient productPublicGrpcClient) { _cache = cache; + _logger = logger; + _mapper = mapper; _productPublicGrpcClient = productPublicGrpcClient; } @@ -33,10 +39,10 @@ public class BasketProductService : BasketServiceAppService, IBasketProductServi private async Task GetProductAsync(Guid productId) { var request = new ProductRequest { Id = productId.ToString() }; - Logger.LogInformation("=== GRPC request {@request}", request); + _logger.LogInformation("=== GRPC request {@request}", request); var response = await _productPublicGrpcClient.GetByIdAsync(request); - Logger.LogInformation("=== GRPC response {@response}", response); - return ObjectMapper.Map(response) ?? + _logger.LogInformation("=== GRPC response {@response}", response); + return _mapper.Map(response) ?? throw new UserFriendlyException(BasketServiceDomainErrorCodes.ProductNotFound); } } \ No newline at end of file From 7a30aa22bcfe24f4b41a16beb176eeb56214a61d Mon Sep 17 00:00:00 2001 From: Galip Tolga Erdem Date: Mon, 7 Feb 2022 11:38:05 +0300 Subject: [PATCH 10/10] Fixed life forgotten lifecycle for integration service --- .../BasketProductService.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/services/basket/src/EShopOnAbp.BasketService.Application/BasketProductService.cs b/services/basket/src/EShopOnAbp.BasketService.Application/BasketProductService.cs index a2d59306..d764b479 100644 --- a/services/basket/src/EShopOnAbp.BasketService.Application/BasketProductService.cs +++ b/services/basket/src/EShopOnAbp.BasketService.Application/BasketProductService.cs @@ -6,10 +6,11 @@ using Microsoft.Extensions.Logging; using Volo.Abp; using Volo.Abp.ObjectMapping; using Volo.Abp.Caching; +using Volo.Abp.DependencyInjection; namespace EShopOnAbp.BasketService; -public class BasketProductService : IBasketProductService +public class BasketProductService : IBasketProductService, ITransientDependency { private readonly IDistributedCache _cache; private readonly ILogger _logger;