Skip to content
This repository was archived by the owner on Nov 17, 2023. It is now read-only.

Commit 3169a93

Browse files
authored
Merge pull request #2107 from dotnet-architecture/davidfowl/common-services
Modernization
2 parents 3ae0cef + df4eb4c commit 3169a93

File tree

314 files changed

+5122
-15990
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

314 files changed

+5122
-15990
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,3 +282,4 @@ src/**/app.yaml
282282
src/**/inf.yaml
283283

284284
.angular/
285+
/src/Services/Identity/Identity.API/keys/*.json

src/ApiGateways/Mobile.Bff.Shopping/aggregator/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ COPY "Services/Ordering/Ordering.Infrastructure/Ordering.Infrastructure.csproj"
3232
COPY "Services/Ordering/Ordering.SignalrHub/Ordering.SignalrHub.csproj" "Services/Ordering/Ordering.SignalrHub/Ordering.SignalrHub.csproj"
3333
COPY "Services/Ordering/Ordering.UnitTests/Ordering.UnitTests.csproj" "Services/Ordering/Ordering.UnitTests/Ordering.UnitTests.csproj"
3434
COPY "Services/Payment/Payment.API/Payment.API.csproj" "Services/Payment/Payment.API/Payment.API.csproj"
35+
COPY "Services/Services.Common/Services.Common.csproj" "Services/Services.Common/Services.Common.csproj"
3536
COPY "Services/Webhooks/Webhooks.API/Webhooks.API.csproj" "Services/Webhooks/Webhooks.API/Webhooks.API.csproj"
3637
COPY "Tests/Services/Application.FunctionalTests/Application.FunctionalTests.csproj" "Tests/Services/Application.FunctionalTests/Application.FunctionalTests.csproj"
3738
COPY "Web/WebhookClient/WebhookClient.csproj" "Web/WebhookClient/WebhookClient.csproj"
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
internal static class Extensions
2+
{
3+
public static IServiceCollection AddReverseProxy(this IServiceCollection services, IConfiguration configuration)
4+
{
5+
services.AddReverseProxy().LoadFromConfig(configuration.GetRequiredSection("ReverseProxy"));
6+
return services;
7+
}
8+
9+
public static IServiceCollection AddHealthChecks(this IServiceCollection services, IConfiguration configuration)
10+
{
11+
services.AddHealthChecks()
12+
.AddUrlGroup(_ => new Uri(configuration.GetRequiredValue("CatalogUrlHC")), name: "catalogapi-check", tags: new string[] { "catalogapi" })
13+
.AddUrlGroup(_ => new Uri(configuration.GetRequiredValue("OrderingUrlHC")), name: "orderingapi-check", tags: new string[] { "orderingapi" })
14+
.AddUrlGroup(_ => new Uri(configuration.GetRequiredValue("BasketUrlHC")), name: "basketapi-check", tags: new string[] { "basketapi" })
15+
.AddUrlGroup(_ => new Uri(configuration.GetRequiredValue("IdentityUrlHC")), name: "identityapi-check", tags: new string[] { "identityapi" });
16+
17+
return services;
18+
}
19+
20+
public static IServiceCollection AddApplicationServices(this IServiceCollection services)
21+
{
22+
// Register delegating handlers
23+
services.AddTransient<HttpClientAuthorizationDelegatingHandler>();
24+
25+
// Register http services
26+
services.AddHttpClient<IOrderApiClient, OrderApiClient>()
27+
.AddHttpMessageHandler<HttpClientAuthorizationDelegatingHandler>();
28+
29+
return services;
30+
}
31+
32+
public static IServiceCollection AddGrpcServices(this IServiceCollection services)
33+
{
34+
services.AddTransient<GrpcExceptionInterceptor>();
35+
36+
services.AddScoped<IBasketService, BasketService>();
37+
38+
services.AddGrpcClient<Basket.BasketClient>((services, options) =>
39+
{
40+
var basketApi = services.GetRequiredService<IOptions<UrlsConfig>>().Value.GrpcBasket;
41+
options.Address = new Uri(basketApi);
42+
}).AddInterceptor<GrpcExceptionInterceptor>();
43+
44+
services.AddScoped<ICatalogService, CatalogService>();
45+
46+
services.AddGrpcClient<Catalog.CatalogClient>((services, options) =>
47+
{
48+
var catalogApi = services.GetRequiredService<IOptions<UrlsConfig>>().Value.GrpcCatalog;
49+
options.Address = new Uri(catalogApi);
50+
}).AddInterceptor<GrpcExceptionInterceptor>();
51+
52+
services.AddScoped<IOrderingService, OrderingService>();
53+
54+
services.AddGrpcClient<GrpcOrdering.OrderingGrpc.OrderingGrpcClient>((services, options) =>
55+
{
56+
var orderingApi = services.GetRequiredService<IOptions<UrlsConfig>>().Value.GrpcOrdering;
57+
options.Address = new Uri(orderingApi);
58+
}).AddInterceptor<GrpcExceptionInterceptor>();
59+
60+
return services;
61+
}
62+
}

src/ApiGateways/Mobile.Bff.Shopping/aggregator/Filters/AuthorizeCheckOperationFilter.cs

Lines changed: 0 additions & 33 deletions
This file was deleted.

src/ApiGateways/Mobile.Bff.Shopping/aggregator/GlobalUsings.cs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,24 @@
22
global using Grpc.Core.Interceptors;
33
global using Grpc.Core;
44
global using GrpcBasket;
5-
global using GrpcOrdering;
65
global using HealthChecks.UI.Client;
76
global using Microsoft.AspNetCore.Authentication.JwtBearer;
87
global using Microsoft.AspNetCore.Authentication;
98
global using Microsoft.AspNetCore.Authorization;
109
global using Microsoft.AspNetCore.Builder;
1110
global using Microsoft.AspNetCore.Diagnostics.HealthChecks;
12-
global using Microsoft.AspNetCore.Hosting;
1311
global using Microsoft.AspNetCore.Http;
1412
global using Microsoft.AspNetCore.Mvc;
15-
global using Microsoft.AspNetCore;
1613
global using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Config;
17-
global using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Filters.Basket.API.Infrastructure.Filters;
1814
global using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Infrastructure;
1915
global using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Models;
2016
global using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Services;
21-
global using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator;
2217
global using Microsoft.Extensions.Configuration;
2318
global using Microsoft.Extensions.DependencyInjection;
2419
global using Microsoft.Extensions.Diagnostics.HealthChecks;
25-
global using Microsoft.Extensions.Hosting;
2620
global using Microsoft.Extensions.Logging;
2721
global using Microsoft.Extensions.Options;
2822
global using Microsoft.OpenApi.Models;
29-
global using Serilog;
30-
global using Swashbuckle.AspNetCore.SwaggerGen;
3123
global using System.Collections.Generic;
3224
global using System.IdentityModel.Tokens.Jwt;
3325
global using System.Linq;
@@ -38,4 +30,5 @@
3830
global using System.Threading.Tasks;
3931
global using System.Threading;
4032
global using System;
41-
global using Microsoft.IdentityModel.Tokens;
33+
global using Microsoft.IdentityModel.Tokens;
34+
global using Services.Common;

src/ApiGateways/Mobile.Bff.Shopping/aggregator/Infrastructure/GrpcExceptionInterceptor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ private async Task<TResponse> HandleResponse<TResponse>(Task<TResponse> t)
2828
}
2929
catch (RpcException e)
3030
{
31-
_logger.LogError("Error calling via grpc: {Status} - {Message}", e.Status, e.Message);
31+
_logger.LogError(e, "Error calling via gRPC: {Status}", e.Status);
3232
return default;
3333
}
3434
}

src/ApiGateways/Mobile.Bff.Shopping/aggregator/Infrastructure/HttpClientAuthorizationDelegatingHandler.cs

Lines changed: 0 additions & 44 deletions
This file was deleted.

src/ApiGateways/Mobile.Bff.Shopping/aggregator/Mobile.Shopping.HttpAggregator.csproj

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,14 @@
1010
</PropertyGroup>
1111

1212
<ItemGroup>
13-
<Folder Include="wwwroot\" />
13+
<Compile Remove="wwwroot\**" />
14+
<Content Remove="wwwroot\**" />
15+
<EmbeddedResource Remove="wwwroot\**" />
16+
<None Remove="wwwroot\**" />
1417
</ItemGroup>
1518

1619
<ItemGroup>
20+
<PackageReference Include="Yarp.ReverseProxy" />
1721
<PackageReference Include="AspNetCore.HealthChecks.UI.Client" />
1822
<PackageReference Include="AspNetCore.HealthChecks.Uris" />
1923
<PackageReference Include="Google.Protobuf" />
@@ -25,11 +29,13 @@
2529
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" />
2630
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.HealthChecks" />
2731
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks" />
28-
<PackageReference Include="Serilog.AspNetCore" />
29-
<PackageReference Include="Serilog.Sinks.Console" />
3032
<PackageReference Include="Swashbuckle.AspNetCore" />
3133
</ItemGroup>
3234

35+
<ItemGroup>
36+
<ProjectReference Include="..\..\..\Services\Services.Common\Services.Common.csproj" />
37+
</ItemGroup>
38+
3339
<ItemGroup>
3440
<Protobuf Include="..\..\..\Services\Basket\Basket.API\Proto\basket.proto" GrpcServices="Client" />
3541
<Protobuf Include="..\..\..\Services\Catalog\Catalog.API\Proto\catalog.proto" GrpcServices="Client" />

src/ApiGateways/Mobile.Bff.Shopping/aggregator/Models/UpdateBasketItemsRequest.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
public class UpdateBasketItemsRequest
44
{
5-
65
public string BasketId { get; set; }
76

87
public ICollection<UpdateBasketItemData> Updates { get; set; }
Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
1-
await BuildWebHost(args).RunAsync();
2-
IWebHost BuildWebHost(string[] args) =>
3-
WebHost
4-
.CreateDefaultBuilder(args)
5-
.ConfigureAppConfiguration(cb =>
6-
{
7-
var sources = cb.Sources;
8-
sources.Insert(3, new Microsoft.Extensions.Configuration.Json.JsonConfigurationSource()
9-
{
10-
Optional = true,
11-
Path = "appsettings.localhost.json",
12-
ReloadOnChange = false
13-
});
14-
})
15-
.UseStartup<Startup>()
16-
.UseSerilog((builderContext, config) =>
17-
{
18-
config
19-
.MinimumLevel.Information()
20-
.Enrich.FromLogContext()
21-
.WriteTo.Console();
22-
})
23-
.Build();
1+
var builder = WebApplication.CreateBuilder(args);
2+
3+
builder.AddServiceDefaults();
4+
5+
builder.Services.AddReverseProxy(builder.Configuration);
6+
builder.Services.AddControllers();
7+
8+
builder.Services.AddHealthChecks(builder.Configuration);
9+
10+
builder.Services.AddApplicationServices();
11+
builder.Services.AddGrpcServices();
12+
13+
builder.Services.Configure<UrlsConfig>(builder.Configuration.GetSection("urls"));
14+
15+
var app = builder.Build();
16+
17+
app.UseServiceDefaults();
18+
19+
app.UseHttpsRedirection();
20+
21+
app.MapControllers();
22+
app.MapReverseProxy();
23+
24+
await app.RunAsync();

0 commit comments

Comments
 (0)