This repository has been archived by the owner on Nov 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1547 from borjasanes/feature/basket-api-migration
basket api net 5 migration
- Loading branch information
Showing
20 changed files
with
355 additions
and
305 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
src/ApiGateways/Mobile.Bff.Shopping/aggregator/Infrastructure/GrpcExceptionInterceptor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using Grpc.Core; | ||
using Grpc.Core.Interceptors; | ||
using Microsoft.Extensions.Logging; | ||
using System; | ||
using System.Threading.Tasks; | ||
|
||
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Infrastructure | ||
{ | ||
public class GrpcExceptionInterceptor : Interceptor | ||
{ | ||
private readonly ILogger<GrpcExceptionInterceptor> _logger; | ||
|
||
public GrpcExceptionInterceptor(ILogger<GrpcExceptionInterceptor> logger) | ||
{ | ||
_logger = logger; | ||
} | ||
|
||
public override AsyncUnaryCall<TResponse> AsyncUnaryCall<TRequest, TResponse>( | ||
TRequest request, | ||
ClientInterceptorContext<TRequest, TResponse> context, | ||
AsyncUnaryCallContinuation<TRequest, TResponse> continuation) | ||
{ | ||
var call = continuation(request, context); | ||
|
||
return new AsyncUnaryCall<TResponse>(HandleResponse(call.ResponseAsync), call.ResponseHeadersAsync, call.GetStatus, call.GetTrailers, call.Dispose); | ||
} | ||
|
||
private async Task<TResponse> HandleResponse<TResponse>(Task<TResponse> t) | ||
{ | ||
try | ||
{ | ||
var response = await t; | ||
_logger.LogDebug($"Response received: {response}"); | ||
return response; | ||
} | ||
catch (RpcException e) | ||
{ | ||
_logger.LogError("Error calling via grpc: {Status} - {Message}", e.Status, e.Message); | ||
return default; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 22 additions & 48 deletions
70
src/ApiGateways/Mobile.Bff.Shopping/aggregator/Program.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,29 @@ | ||
using Microsoft.AspNetCore; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator; | ||
using Serilog; | ||
using System.IO; | ||
|
||
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator | ||
{ | ||
public class Program | ||
{ | ||
private static IConfiguration _configuration; | ||
|
||
public static void Main(string[] args) | ||
BuildWebHost(args).Run(); | ||
IWebHost BuildWebHost(string[] args) => | ||
WebHost | ||
.CreateDefaultBuilder(args) | ||
.ConfigureAppConfiguration(cb => | ||
{ | ||
_configuration = GetConfiguration(); | ||
|
||
BuildWebHost(args).Run(); | ||
} | ||
|
||
public static IWebHost BuildWebHost(string[] args) => | ||
WebHost | ||
.CreateDefaultBuilder(args) | ||
.ConfigureAppConfiguration(cb => | ||
{ | ||
var sources = cb.Sources; | ||
sources.Insert(3, new Microsoft.Extensions.Configuration.Json.JsonConfigurationSource() | ||
{ | ||
Optional = true, | ||
Path = "appsettings.localhost.json", | ||
ReloadOnChange = false | ||
}); | ||
}) | ||
.UseStartup<Startup>() | ||
.UseSerilog((builderContext, config) => | ||
{ | ||
config | ||
.MinimumLevel.Information() | ||
.Enrich.FromLogContext() | ||
.WriteTo.Console(); | ||
}) | ||
.Build(); | ||
|
||
private static IConfiguration GetConfiguration() | ||
var sources = cb.Sources; | ||
sources.Insert(3, new Microsoft.Extensions.Configuration.Json.JsonConfigurationSource() | ||
{ | ||
Optional = true, | ||
Path = "appsettings.localhost.json", | ||
ReloadOnChange = false | ||
}); | ||
}) | ||
.UseStartup<Startup>() | ||
.UseSerilog((builderContext, config) => | ||
{ | ||
var builder = new ConfigurationBuilder() | ||
.SetBasePath(Directory.GetCurrentDirectory()) | ||
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) | ||
.AddEnvironmentVariables(); | ||
|
||
var config = builder.Build(); | ||
|
||
return builder.Build(); | ||
} | ||
} | ||
} | ||
config | ||
.MinimumLevel.Information() | ||
.Enrich.FromLogContext() | ||
.WriteTo.Console(); | ||
}) | ||
.Build(); |
38 changes: 12 additions & 26 deletions
38
src/ApiGateways/Mobile.Bff.Shopping/aggregator/Services/BasketService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/ApiGateways/Web.Bff.Shopping/aggregator/Infrastructure/GrpcExceptionInterceptor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using Grpc.Core; | ||
using Grpc.Core.Interceptors; | ||
using Microsoft.Extensions.Logging; | ||
using System; | ||
using System.Threading.Tasks; | ||
|
||
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Infrastructure | ||
{ | ||
public class GrpcExceptionInterceptor : Interceptor | ||
{ | ||
private readonly ILogger<GrpcExceptionInterceptor> _logger; | ||
|
||
public GrpcExceptionInterceptor(ILogger<GrpcExceptionInterceptor> logger) | ||
{ | ||
_logger = logger; | ||
} | ||
|
||
public override AsyncUnaryCall<TResponse> AsyncUnaryCall<TRequest, TResponse>( | ||
TRequest request, | ||
ClientInterceptorContext<TRequest, TResponse> context, | ||
AsyncUnaryCallContinuation<TRequest, TResponse> continuation) | ||
{ | ||
var call = continuation(request, context); | ||
|
||
return new AsyncUnaryCall<TResponse>(HandleResponse(call.ResponseAsync), call.ResponseHeadersAsync, call.GetStatus, call.GetTrailers, call.Dispose); | ||
} | ||
|
||
private async Task<TResponse> HandleResponse<TResponse>(Task<TResponse> t) | ||
{ | ||
try | ||
{ | ||
var response = await t; | ||
_logger.LogDebug($"Response received: {response}"); | ||
return response; | ||
} | ||
catch (RpcException e) | ||
{ | ||
_logger.LogError("Error calling via grpc: {Status} - {Message}", e.Status, e.Message); | ||
return default; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,29 @@ | ||
using Microsoft.AspNetCore; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator; | ||
using Serilog; | ||
|
||
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator | ||
{ | ||
public class Program | ||
{ | ||
public static void Main(string[] args) | ||
{ | ||
BuildWebHost(args).Run(); | ||
} | ||
|
||
public static IWebHost BuildWebHost(string[] args) => | ||
WebHost | ||
.CreateDefaultBuilder(args) | ||
.ConfigureAppConfiguration(cb => | ||
{ | ||
var sources = cb.Sources; | ||
sources.Insert(3, new Microsoft.Extensions.Configuration.Json.JsonConfigurationSource() | ||
{ | ||
Optional = true, | ||
Path = "appsettings.localhost.json", | ||
ReloadOnChange = false | ||
}); | ||
}) | ||
.UseStartup<Startup>() | ||
.UseSerilog((builderContext, config) => | ||
{ | ||
config | ||
.MinimumLevel.Information() | ||
.Enrich.FromLogContext() | ||
.WriteTo.Console(); | ||
}) | ||
.Build(); | ||
BuildWebHost(args).Run(); | ||
|
||
} | ||
} | ||
IWebHost BuildWebHost(string[] args) => | ||
WebHost | ||
.CreateDefaultBuilder(args) | ||
.ConfigureAppConfiguration(cb => | ||
{ | ||
var sources = cb.Sources; | ||
sources.Insert(3, new Microsoft.Extensions.Configuration.Json.JsonConfigurationSource() | ||
{ | ||
Optional = true, | ||
Path = "appsettings.localhost.json", | ||
ReloadOnChange = false | ||
}); | ||
}) | ||
.UseStartup<Startup>() | ||
.UseSerilog((builderContext, config) => | ||
{ | ||
config | ||
.MinimumLevel.Information() | ||
.Enrich.FromLogContext() | ||
.WriteTo.Console(); | ||
}) | ||
.Build(); |
Oops, something went wrong.