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

Modernization #2107

Merged
merged 118 commits into from
May 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
118 commits
Select commit Hold shift + click to select a range
746363b
Remove accidentally committed keys and update .gitignore to prevent t…
ReubenBond Apr 28, 2023
d91da03
Fix IncludeScopes setting in appsettings.json for WebSPA
ReubenBond Apr 28, 2023
1098539
Remove gRPC generated code from global usings etc
ReubenBond Apr 28, 2023
d62ebcb
Fix IncludeScopes
ReubenBond Apr 28, 2023
91247ec
BAD MISC - playing with tests
ReubenBond Apr 28, 2023
f3d2843
Make tests work
davidfowl May 1, 2023
746e5da
Make more tests pass
davidfowl May 1, 2023
d4c2f17
Remove whitespace
davidfowl May 1, 2023
233b6e5
Fixed catalog functional tests
davidfowl May 1, 2023
c7edd50
Fix ordering and basked scenarios
davidfowl May 2, 2023
e7e0eed
Fixed remaining tests
davidfowl May 2, 2023
9af6d63
Initial attempt at making a common service configuration
davidfowl May 2, 2023
00fc3d8
More defaults
davidfowl May 2, 2023
3fee612
More tweaks
davidfowl May 2, 2023
8a40e9f
More schema
davidfowl May 2, 2023
57a93f6
More customization
davidfowl May 3, 2023
9d52426
Use default logger
davidfowl May 3, 2023
7da7e98
Configure so tests work again
davidfowl May 3, 2023
d1372cb
First pass at making the catalog API use the common service helpers
davidfowl May 3, 2023
f46b03c
Use before Map
davidfowl May 3, 2023
794c546
Fix the catalog tests
davidfowl May 3, 2023
c565a8f
Unify configuration
davidfowl May 3, 2023
d4319bd
Redirect to swagger
davidfowl May 3, 2023
366019a
Use the assembly name instead of the type name
davidfowl May 3, 2023
4e743ef
Not needed
davidfowl May 3, 2023
48f6400
More clean up
davidfowl May 3, 2023
bff8080
Remove the UseVault and use the existance of the section
davidfowl May 3, 2023
45a04e4
Make services run individually and outside of docker
davidfowl May 4, 2023
41056e5
Update grpc reference
davidfowl May 4, 2023
b48ba7b
More clean up
davidfowl May 4, 2023
56d47db
Read from the connection strings section
davidfowl May 4, 2023
c59e668
- Add redis health check
davidfowl May 4, 2023
d96e4db
Remove Program
davidfowl May 4, 2023
7d28625
Remove Serilog from Web.Shopping.HttpAggregator
ReubenBond May 4, 2023
3f5f0b9
Remove Program from Catalog.API
ReubenBond May 4, 2023
5342c86
Remove Serilog from Identity.API and clean up
ReubenBond May 4, 2023
8da0a81
Remove Serilog usage
ReubenBond May 4, 2023
da024f9
Remove Program.AppName
ReubenBond May 4, 2023
02c1632
Add EventBus connection string to Catalog.API
ReubenBond May 4, 2023
b9f48fa
Use simpler syntax for default
ReubenBond May 4, 2023
fea08c7
Finish removing Autofac
ReubenBond May 4, 2023
83200f9
Fix Dockerfiles to include Services.Common
ReubenBond May 4, 2023
16b6300
Add Identity sections to config and consume (likely broken). Simplify…
ReubenBond May 4, 2023
f8abb36
Remove non-existent wwwroot from HttpAggregator projects
ReubenBond May 4, 2023
e2d8590
Use WebApplicationBuilder in Mobile.Shopping.HttpAggregator
ReubenBond May 4, 2023
9177642
Remove superfluous UseDeveloperExceptionPage() and AddOptions() calls
ReubenBond May 4, 2023
3056418
Made a health check api
davidfowl May 4, 2023
a381a69
Removed filters and special errors handling from MVC
davidfowl May 4, 2023
34fc949
Small clean up to error handling code
davidfowl May 4, 2023
0fd20ee
More clean up
davidfowl May 4, 2023
5397e8d
Made small tweak to startup
davidfowl May 4, 2023
cf02e90
Migrate from ILoggerFactory to ILogger<T> and use Logging Source Gene…
ReubenBond May 4, 2023
ccaad9d
Removed unneeded project deps
davidfowl May 5, 2023
7681405
More clean up
davidfowl May 5, 2023
08e7c34
Delete more cruft
davidfowl May 5, 2023
a415605
Split redis and health checks for redis
davidfowl May 5, 2023
909f086
Make the ordering API use the commmon services
davidfowl May 5, 2023
3357c70
Clean up excess in project file
davidfowl May 5, 2023
6e69a24
Small naming tweaks for consistency
davidfowl May 5, 2023
9743c83
Use the common services in the Ordering.SignalRHub project
davidfowl May 5, 2023
0cb6b08
Clean up the project
davidfowl May 5, 2023
c41cd38
Updated background tasks to use common service logic
davidfowl May 5, 2023
2a4a6ab
Small tweaks
davidfowl May 5, 2023
a37b043
Remove unneeded dependencies
davidfowl May 5, 2023
57d9baf
Make the payment API use the common code
davidfowl May 5, 2023
bcb1374
Avoid logging exception details twice in a given log, clean up
ReubenBond May 5, 2023
e166b28
Update the webhooks project to use service common
davidfowl May 5, 2023
7027967
More random clean up
davidfowl May 5, 2023
acd9a6d
Clean up the identity project and make it use services common
davidfowl May 6, 2023
5ea0341
Move extensions to Extensions folder
davidfowl May 6, 2023
031996d
Fixed check
davidfowl May 6, 2023
3c00be3
Make BFF work and clean up ports
davidfowl May 6, 2023
d086d27
Moved repository to top level folder
davidfowl May 6, 2023
6b89921
Rename extensions to extensions
davidfowl May 6, 2023
e1ec790
Make more things work with docker compose
davidfowl May 6, 2023
d0c710e
Docker compose works
davidfowl May 6, 2023
69b28c6
Added gRPC and HTTP endpoints via config
davidfowl May 6, 2023
670a945
Remove health check
davidfowl May 7, 2023
5a2d385
Fixed identity url
davidfowl May 7, 2023
f76a8c6
Make default URLs work
davidfowl May 7, 2023
50952be
Sort usings and delete web.config
davidfowl May 7, 2023
06d74d1
Small tweaks to make the MVC application run locally
davidfowl May 7, 2023
30ed001
Added YARP as an API gateway
davidfowl May 7, 2023
c3efea0
Add YARP to the BFF directly.
davidfowl May 7, 2023
6a2fceb
Fix more urls
davidfowl May 8, 2023
561d48b
Fix cors and prefix rewriting
davidfowl May 8, 2023
84c6b11
Remove cors from the signalr service
davidfowl May 8, 2023
bd74512
Added comment about allowed origins
davidfowl May 8, 2023
758d4bb
Specify routes in config
davidfowl May 8, 2023
69476a3
Use the default YARP configuration
davidfowl May 8, 2023
64a2d69
Use YARP native config
davidfowl May 8, 2023
62a6f17
Removed unneeded usings
davidfowl May 8, 2023
40315c6
Make docker use the reverse proxy
davidfowl May 8, 2023
8c2ca8d
Make WebMVC use the service common helpers
davidfowl May 8, 2023
0a07aea
Small refactoring of the helper methods
davidfowl May 8, 2023
a7cdb1d
Remove unused code
davidfowl May 8, 2023
992b58d
Fixed cookies
davidfowl May 8, 2023
6933d99
Forward SignalR requests through the web app
davidfowl May 8, 2023
af42aab
Don't launch the browser for signalr
davidfowl May 8, 2023
184ed15
Clean up the auth delegating handler
davidfowl May 8, 2023
bdebee7
Clean up SignIn action
davidfowl May 8, 2023
6ad5e8f
Deleted test controller
davidfowl May 8, 2023
8debda5
Don't read the file into memory
davidfowl May 8, 2023
d5533c0
Move the pic controller to a minimal API
davidfowl May 8, 2023
89a42e6
Removed session since its not used
davidfowl May 8, 2023
52cdd16
Fix Handler_sends_no_command_when_order_already_exists test
ReubenBond May 8, 2023
a87efde
Small nit
davidfowl May 8, 2023
3858d7c
Fix integration tests
ReubenBond May 8, 2023
9c2b972
Correctly set scopes for AuthorizeCheckOperationFilter
ReubenBond May 8, 2023
8c9524c
Reduce double writes in Application.FunctionalTests build
ReubenBond May 8, 2023
72c8167
Attempt to migrate Mobile BFF to common services pattern
ReubenBond May 8, 2023
f5218e8
Start adding connection strings for VS launch profile
ReubenBond May 8, 2023
8f9f9d1
Add libman package to WebMVC to fix site
ReubenBond May 8, 2023
6ebde3f
Remove on-start health check in Ordering.BackgroundTasks so that it d…
ReubenBond May 8, 2023
dbef61f
Nuke the cors from the mobile BFF
davidfowl May 8, 2023
6f4ae50
Port WebhookClient to WebApplicationBuilder
ReubenBond May 8, 2023
e4b94de
Use Services.Common in WebhookClient
ReubenBond May 8, 2023
df4eb4c
More code sharing and clean up WebHooks client
davidfowl May 9, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -282,3 +282,4 @@ src/**/app.yaml
src/**/inf.yaml

.angular/
/src/Services/Identity/Identity.API/keys/*.json
1 change: 1 addition & 0 deletions src/ApiGateways/Mobile.Bff.Shopping/aggregator/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ COPY "Services/Ordering/Ordering.Infrastructure/Ordering.Infrastructure.csproj"
COPY "Services/Ordering/Ordering.SignalrHub/Ordering.SignalrHub.csproj" "Services/Ordering/Ordering.SignalrHub/Ordering.SignalrHub.csproj"
COPY "Services/Ordering/Ordering.UnitTests/Ordering.UnitTests.csproj" "Services/Ordering/Ordering.UnitTests/Ordering.UnitTests.csproj"
COPY "Services/Payment/Payment.API/Payment.API.csproj" "Services/Payment/Payment.API/Payment.API.csproj"
COPY "Services/Services.Common/Services.Common.csproj" "Services/Services.Common/Services.Common.csproj"
COPY "Services/Webhooks/Webhooks.API/Webhooks.API.csproj" "Services/Webhooks/Webhooks.API/Webhooks.API.csproj"
COPY "Tests/Services/Application.FunctionalTests/Application.FunctionalTests.csproj" "Tests/Services/Application.FunctionalTests/Application.FunctionalTests.csproj"
COPY "Web/WebhookClient/WebhookClient.csproj" "Web/WebhookClient/WebhookClient.csproj"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
internal static class Extensions
{
public static IServiceCollection AddReverseProxy(this IServiceCollection services, IConfiguration configuration)
{
services.AddReverseProxy().LoadFromConfig(configuration.GetRequiredSection("ReverseProxy"));
return services;
}

public static IServiceCollection AddHealthChecks(this IServiceCollection services, IConfiguration configuration)
{
services.AddHealthChecks()
.AddUrlGroup(_ => new Uri(configuration.GetRequiredValue("CatalogUrlHC")), name: "catalogapi-check", tags: new string[] { "catalogapi" })
.AddUrlGroup(_ => new Uri(configuration.GetRequiredValue("OrderingUrlHC")), name: "orderingapi-check", tags: new string[] { "orderingapi" })
.AddUrlGroup(_ => new Uri(configuration.GetRequiredValue("BasketUrlHC")), name: "basketapi-check", tags: new string[] { "basketapi" })
.AddUrlGroup(_ => new Uri(configuration.GetRequiredValue("IdentityUrlHC")), name: "identityapi-check", tags: new string[] { "identityapi" });

return services;
}

public static IServiceCollection AddApplicationServices(this IServiceCollection services)
{
// Register delegating handlers
services.AddTransient<HttpClientAuthorizationDelegatingHandler>();

// Register http services
services.AddHttpClient<IOrderApiClient, OrderApiClient>()
.AddHttpMessageHandler<HttpClientAuthorizationDelegatingHandler>();

return services;
}

public static IServiceCollection AddGrpcServices(this IServiceCollection services)
{
services.AddTransient<GrpcExceptionInterceptor>();

services.AddScoped<IBasketService, BasketService>();

services.AddGrpcClient<Basket.BasketClient>((services, options) =>
{
var basketApi = services.GetRequiredService<IOptions<UrlsConfig>>().Value.GrpcBasket;
options.Address = new Uri(basketApi);
}).AddInterceptor<GrpcExceptionInterceptor>();

services.AddScoped<ICatalogService, CatalogService>();

services.AddGrpcClient<Catalog.CatalogClient>((services, options) =>
{
var catalogApi = services.GetRequiredService<IOptions<UrlsConfig>>().Value.GrpcCatalog;
options.Address = new Uri(catalogApi);
}).AddInterceptor<GrpcExceptionInterceptor>();

services.AddScoped<IOrderingService, OrderingService>();

services.AddGrpcClient<GrpcOrdering.OrderingGrpc.OrderingGrpcClient>((services, options) =>
{
var orderingApi = services.GetRequiredService<IOptions<UrlsConfig>>().Value.GrpcOrdering;
options.Address = new Uri(orderingApi);
}).AddInterceptor<GrpcExceptionInterceptor>();

return services;
}
}

This file was deleted.

11 changes: 2 additions & 9 deletions src/ApiGateways/Mobile.Bff.Shopping/aggregator/GlobalUsings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,24 @@
global using Grpc.Core.Interceptors;
global using Grpc.Core;
global using GrpcBasket;
global using GrpcOrdering;
global using HealthChecks.UI.Client;
global using Microsoft.AspNetCore.Authentication.JwtBearer;
global using Microsoft.AspNetCore.Authentication;
global using Microsoft.AspNetCore.Authorization;
global using Microsoft.AspNetCore.Builder;
global using Microsoft.AspNetCore.Diagnostics.HealthChecks;
global using Microsoft.AspNetCore.Hosting;
global using Microsoft.AspNetCore.Http;
global using Microsoft.AspNetCore.Mvc;
global using Microsoft.AspNetCore;
global using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Config;
global using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Filters.Basket.API.Infrastructure.Filters;
global using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Infrastructure;
global using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Models;
global using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Services;
global using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator;
global using Microsoft.Extensions.Configuration;
global using Microsoft.Extensions.DependencyInjection;
global using Microsoft.Extensions.Diagnostics.HealthChecks;
global using Microsoft.Extensions.Hosting;
global using Microsoft.Extensions.Logging;
global using Microsoft.Extensions.Options;
global using Microsoft.OpenApi.Models;
global using Serilog;
global using Swashbuckle.AspNetCore.SwaggerGen;
global using System.Collections.Generic;
global using System.IdentityModel.Tokens.Jwt;
global using System.Linq;
Expand All @@ -38,4 +30,5 @@
global using System.Threading.Tasks;
global using System.Threading;
global using System;
global using Microsoft.IdentityModel.Tokens;
global using Microsoft.IdentityModel.Tokens;
global using Services.Common;
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ private async Task<TResponse> HandleResponse<TResponse>(Task<TResponse> t)
}
catch (RpcException e)
{
_logger.LogError("Error calling via grpc: {Status} - {Message}", e.Status, e.Message);
_logger.LogError(e, "Error calling via gRPC: {Status}", e.Status);
return default;
}
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@
</PropertyGroup>

<ItemGroup>
<Folder Include="wwwroot\" />
<Compile Remove="wwwroot\**" />
<Content Remove="wwwroot\**" />
<EmbeddedResource Remove="wwwroot\**" />
<None Remove="wwwroot\**" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Yarp.ReverseProxy" />
<PackageReference Include="AspNetCore.HealthChecks.UI.Client" />
<PackageReference Include="AspNetCore.HealthChecks.Uris" />
<PackageReference Include="Google.Protobuf" />
Expand All @@ -25,11 +29,13 @@
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.HealthChecks" />
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks" />
<PackageReference Include="Serilog.AspNetCore" />
<PackageReference Include="Serilog.Sinks.Console" />
<PackageReference Include="Swashbuckle.AspNetCore" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\Services\Services.Common\Services.Common.csproj" />
</ItemGroup>

<ItemGroup>
<Protobuf Include="..\..\..\Services\Basket\Basket.API\Proto\basket.proto" GrpcServices="Client" />
<Protobuf Include="..\..\..\Services\Catalog\Catalog.API\Proto\catalog.proto" GrpcServices="Client" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

public class UpdateBasketItemsRequest
{

public string BasketId { get; set; }

public ICollection<UpdateBasketItemData> Updates { get; set; }
Expand Down
47 changes: 24 additions & 23 deletions src/ApiGateways/Mobile.Bff.Shopping/aggregator/Program.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
await BuildWebHost(args).RunAsync();
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();
var builder = WebApplication.CreateBuilder(args);

builder.AddServiceDefaults();

builder.Services.AddReverseProxy(builder.Configuration);
builder.Services.AddControllers();

builder.Services.AddHealthChecks(builder.Configuration);

builder.Services.AddApplicationServices();
builder.Services.AddGrpcServices();

builder.Services.Configure<UrlsConfig>(builder.Configuration.GetSection("urls"));

var app = builder.Build();

app.UseServiceDefaults();

app.UseHttpsRedirection();

app.MapControllers();
app.MapReverseProxy();

await app.RunAsync();
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ public interface IBasketService
Task<BasketData> GetByIdAsync(string id);

Task UpdateAsync(BasketData currentBasket);

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

public class OrderingService : IOrderingService
{
private readonly OrderingGrpc.OrderingGrpcClient _orderingGrpcClient;
private readonly GrpcOrdering.OrderingGrpc.OrderingGrpcClient _orderingGrpcClient;
private readonly ILogger<OrderingService> _logger;

public OrderingService(OrderingGrpc.OrderingGrpcClient orderingGrpcClient, ILogger<OrderingService> logger)
public OrderingService(GrpcOrdering.OrderingGrpc.OrderingGrpcClient orderingGrpcClient, ILogger<OrderingService> logger)
{
_orderingGrpcClient = orderingGrpcClient;
_logger = logger;
Expand Down Expand Up @@ -48,14 +48,14 @@ private OrderData MapToResponse(GrpcOrdering.OrderDraftDTO orderDraft, BasketDat
return data;
}

private CreateOrderDraftCommand MapToOrderDraftCommand(BasketData basketData)
private GrpcOrdering.CreateOrderDraftCommand MapToOrderDraftCommand(BasketData basketData)
{
var command = new CreateOrderDraftCommand
var command = new GrpcOrdering.CreateOrderDraftCommand
{
BuyerId = basketData.BuyerId,
};

basketData.Items.ForEach(i => command.Items.Add(new BasketItem
basketData.Items.ForEach(i => command.Items.Add(new GrpcOrdering.BasketItem
{
Id = i.Id,
OldUnitPrice = (double)i.OldUnitPrice,
Expand Down
Loading
Loading