Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions BFF/v4/MultiFrontend/AppHost/AppHost.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright (c) Duende Software. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

var builder = DistributedApplication.CreateBuilder(args);

var bff = builder.AddProject<Projects.bff>("bff");

var api = builder.AddProject<Projects.api>("api");

var customerPortal = builder.AddNpmApp("customer-portal", "../frontends/customer-portal", "dev")
.WithEndpoint(5175, isProxied: false, scheme: "https"); ;
var managementApp = builder.AddNpmApp("management-app", "../frontends/management-app", "dev")
.WithEndpoint(5173, isProxied: false, scheme: "https");

bff
.WithReference(api)
.WithReference(managementApp)
.WithReference(customerPortal);

builder.Build().Run();
24 changes: 24 additions & 0 deletions BFF/v4/MultiFrontend/AppHost/AppHost.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">

<Sdk Name="Aspire.AppHost.Sdk" Version="9.3.1" />

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<UserSecretsId>640a71f0-d6bd-49ed-a9ee-c8201562c94c</UserSecretsId>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Aspire.Hosting.AppHost" Version="9.3.1" />
<PackageReference Include="Aspire.Hosting.NodeJs" Version="9.4.2" />

</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\api\api.csproj" />
<ProjectReference Include="..\bff\bff.csproj" />
</ItemGroup>

</Project>
29 changes: 29 additions & 0 deletions BFF/v4/MultiFrontend/AppHost/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"profiles": {
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": false,
"applicationUrl": "https://localhost:17021;http://localhost:15063",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"DOTNET_ENVIRONMENT": "Development",
"ASPIRE_DASHBOARD_OTLP_ENDPOINT_URL": "https://localhost:21154",
"ASPIRE_RESOURCE_SERVICE_ENDPOINT_URL": "https://localhost:22013"
}
},
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": false,
"applicationUrl": "http://localhost:15063",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"DOTNET_ENVIRONMENT": "Development",
"ASPIRE_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:19177",
"ASPIRE_RESOURCE_SERVICE_ENDPOINT_URL": "http://localhost:20040"
}
}
}
}
8 changes: 8 additions & 0 deletions BFF/v4/MultiFrontend/AppHost/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
9 changes: 9 additions & 0 deletions BFF/v4/MultiFrontend/AppHost/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning",
"Aspire.Hosting.Dcp": "Warning"
}
}
}
79 changes: 79 additions & 0 deletions BFF/v4/MultiFrontend/MultiFrontend.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "api", "api\api.csproj", "{B7FF8755-BB49-4A17-B3FC-E9954D530076}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "bff", "bff\bff.csproj", "{E9CD6498-D706-414D-9A3F-3899A994441D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AppHost", "AppHost\AppHost.csproj", "{299F3C6A-2537-4C0C-A404-479F16C8960B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ServiceDefaults", "ServiceDefaults\ServiceDefaults.csproj", "{D3AFD96D-CE25-447D-A587-F20BF30C8486}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{B7FF8755-BB49-4A17-B3FC-E9954D530076}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B7FF8755-BB49-4A17-B3FC-E9954D530076}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B7FF8755-BB49-4A17-B3FC-E9954D530076}.Debug|x64.ActiveCfg = Debug|Any CPU
{B7FF8755-BB49-4A17-B3FC-E9954D530076}.Debug|x64.Build.0 = Debug|Any CPU
{B7FF8755-BB49-4A17-B3FC-E9954D530076}.Debug|x86.ActiveCfg = Debug|Any CPU
{B7FF8755-BB49-4A17-B3FC-E9954D530076}.Debug|x86.Build.0 = Debug|Any CPU
{B7FF8755-BB49-4A17-B3FC-E9954D530076}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B7FF8755-BB49-4A17-B3FC-E9954D530076}.Release|Any CPU.Build.0 = Release|Any CPU
{B7FF8755-BB49-4A17-B3FC-E9954D530076}.Release|x64.ActiveCfg = Release|Any CPU
{B7FF8755-BB49-4A17-B3FC-E9954D530076}.Release|x64.Build.0 = Release|Any CPU
{B7FF8755-BB49-4A17-B3FC-E9954D530076}.Release|x86.ActiveCfg = Release|Any CPU
{B7FF8755-BB49-4A17-B3FC-E9954D530076}.Release|x86.Build.0 = Release|Any CPU
{E9CD6498-D706-414D-9A3F-3899A994441D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E9CD6498-D706-414D-9A3F-3899A994441D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E9CD6498-D706-414D-9A3F-3899A994441D}.Debug|x64.ActiveCfg = Debug|Any CPU
{E9CD6498-D706-414D-9A3F-3899A994441D}.Debug|x64.Build.0 = Debug|Any CPU
{E9CD6498-D706-414D-9A3F-3899A994441D}.Debug|x86.ActiveCfg = Debug|Any CPU
{E9CD6498-D706-414D-9A3F-3899A994441D}.Debug|x86.Build.0 = Debug|Any CPU
{E9CD6498-D706-414D-9A3F-3899A994441D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E9CD6498-D706-414D-9A3F-3899A994441D}.Release|Any CPU.Build.0 = Release|Any CPU
{E9CD6498-D706-414D-9A3F-3899A994441D}.Release|x64.ActiveCfg = Release|Any CPU
{E9CD6498-D706-414D-9A3F-3899A994441D}.Release|x64.Build.0 = Release|Any CPU
{E9CD6498-D706-414D-9A3F-3899A994441D}.Release|x86.ActiveCfg = Release|Any CPU
{E9CD6498-D706-414D-9A3F-3899A994441D}.Release|x86.Build.0 = Release|Any CPU
{299F3C6A-2537-4C0C-A404-479F16C8960B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{299F3C6A-2537-4C0C-A404-479F16C8960B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{299F3C6A-2537-4C0C-A404-479F16C8960B}.Debug|x64.ActiveCfg = Debug|Any CPU
{299F3C6A-2537-4C0C-A404-479F16C8960B}.Debug|x64.Build.0 = Debug|Any CPU
{299F3C6A-2537-4C0C-A404-479F16C8960B}.Debug|x86.ActiveCfg = Debug|Any CPU
{299F3C6A-2537-4C0C-A404-479F16C8960B}.Debug|x86.Build.0 = Debug|Any CPU
{299F3C6A-2537-4C0C-A404-479F16C8960B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{299F3C6A-2537-4C0C-A404-479F16C8960B}.Release|Any CPU.Build.0 = Release|Any CPU
{299F3C6A-2537-4C0C-A404-479F16C8960B}.Release|x64.ActiveCfg = Release|Any CPU
{299F3C6A-2537-4C0C-A404-479F16C8960B}.Release|x64.Build.0 = Release|Any CPU
{299F3C6A-2537-4C0C-A404-479F16C8960B}.Release|x86.ActiveCfg = Release|Any CPU
{299F3C6A-2537-4C0C-A404-479F16C8960B}.Release|x86.Build.0 = Release|Any CPU
{D3AFD96D-CE25-447D-A587-F20BF30C8486}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D3AFD96D-CE25-447D-A587-F20BF30C8486}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D3AFD96D-CE25-447D-A587-F20BF30C8486}.Debug|x64.ActiveCfg = Debug|Any CPU
{D3AFD96D-CE25-447D-A587-F20BF30C8486}.Debug|x64.Build.0 = Debug|Any CPU
{D3AFD96D-CE25-447D-A587-F20BF30C8486}.Debug|x86.ActiveCfg = Debug|Any CPU
{D3AFD96D-CE25-447D-A587-F20BF30C8486}.Debug|x86.Build.0 = Debug|Any CPU
{D3AFD96D-CE25-447D-A587-F20BF30C8486}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D3AFD96D-CE25-447D-A587-F20BF30C8486}.Release|Any CPU.Build.0 = Release|Any CPU
{D3AFD96D-CE25-447D-A587-F20BF30C8486}.Release|x64.ActiveCfg = Release|Any CPU
{D3AFD96D-CE25-447D-A587-F20BF30C8486}.Release|x64.Build.0 = Release|Any CPU
{D3AFD96D-CE25-447D-A587-F20BF30C8486}.Release|x86.ActiveCfg = Release|Any CPU
{D3AFD96D-CE25-447D-A587-F20BF30C8486}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {DF500587-F054-46FE-8A4F-A24127AF8905}
EndGlobalSection
EndGlobal
129 changes: 129 additions & 0 deletions BFF/v4/MultiFrontend/ServiceDefaults/Extensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
// Copyright (c) Duende Software. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Diagnostics.HealthChecks;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.ServiceDiscovery;
using OpenTelemetry;
using OpenTelemetry.Metrics;
using OpenTelemetry.Trace;

namespace Microsoft.Extensions.Hosting;
// Adds common .NET Aspire services: service discovery, resilience, health checks, and OpenTelemetry.
// This project should be referenced by each service project in your solution.
// To learn more about using this project, see https://aka.ms/dotnet/aspire/service-defaults
public static class Extensions
{
private const string HealthEndpointPath = "/health";
private const string AlivenessEndpointPath = "/alive";

public static TBuilder AddServiceDefaults<TBuilder>(this TBuilder builder) where TBuilder : IHostApplicationBuilder
{
builder.ConfigureOpenTelemetry();

builder.AddDefaultHealthChecks();

builder.Services.AddServiceDiscovery();

builder.Services.ConfigureHttpClientDefaults(http =>
{
// Turn on resilience by default
http.AddStandardResilienceHandler();

// Turn on service discovery by default
http.AddServiceDiscovery();
});

// Uncomment the following to restrict the allowed schemes for service discovery.
// builder.Services.Configure<ServiceDiscoveryOptions>(options =>
// {
// options.AllowedSchemes = ["https"];
// });

return builder;
}

public static TBuilder ConfigureOpenTelemetry<TBuilder>(this TBuilder builder) where TBuilder : IHostApplicationBuilder
{
builder.Logging.AddOpenTelemetry(logging =>
{
logging.IncludeFormattedMessage = true;
logging.IncludeScopes = true;
});

builder.Services.AddOpenTelemetry()
.WithMetrics(metrics =>
{
metrics.AddAspNetCoreInstrumentation()
.AddHttpClientInstrumentation()
.AddRuntimeInstrumentation();
})
.WithTracing(tracing =>
{
tracing.AddSource(builder.Environment.ApplicationName)
.AddAspNetCoreInstrumentation(tracing =>
// Exclude health check requests from tracing
tracing.Filter = context =>
!context.Request.Path.StartsWithSegments(HealthEndpointPath)
&& !context.Request.Path.StartsWithSegments(AlivenessEndpointPath)
)
// Uncomment the following line to enable gRPC instrumentation (requires the OpenTelemetry.Instrumentation.GrpcNetClient package)
//.AddGrpcClientInstrumentation()
.AddHttpClientInstrumentation();
});

builder.AddOpenTelemetryExporters();

return builder;
}

private static TBuilder AddOpenTelemetryExporters<TBuilder>(this TBuilder builder) where TBuilder : IHostApplicationBuilder
{
var useOtlpExporter = !string.IsNullOrWhiteSpace(builder.Configuration["OTEL_EXPORTER_OTLP_ENDPOINT"]);

if (useOtlpExporter)
{
builder.Services.AddOpenTelemetry().UseOtlpExporter();
}

// Uncomment the following lines to enable the Azure Monitor exporter (requires the Azure.Monitor.OpenTelemetry.AspNetCore package)
//if (!string.IsNullOrEmpty(builder.Configuration["APPLICATIONINSIGHTS_CONNECTION_STRING"]))
//{
// builder.Services.AddOpenTelemetry()
// .UseAzureMonitor();
//}

return builder;
}

public static TBuilder AddDefaultHealthChecks<TBuilder>(this TBuilder builder) where TBuilder : IHostApplicationBuilder
{
builder.Services.AddHealthChecks()
// Add a default liveness check to ensure app is responsive
.AddCheck("self", () => HealthCheckResult.Healthy(), ["live"]);

return builder;
}

public static WebApplication MapDefaultEndpoints(this WebApplication app)
{
// Adding health checks endpoints to applications in non-development environments has security implications.
// See https://aka.ms/dotnet/aspire/healthchecks for details before enabling these endpoints in non-development environments.
if (app.Environment.IsDevelopment())
{
// All health checks must pass for app to be considered ready to accept traffic after starting
app.MapHealthChecks(HealthEndpointPath);

// Only health checks tagged with the "live" tag must pass for app to be considered alive
app.MapHealthChecks(AlivenessEndpointPath, new HealthCheckOptions
{
Predicate = r => r.Tags.Contains("live")
});
}

return app;
}
}
22 changes: 22 additions & 0 deletions BFF/v4/MultiFrontend/ServiceDefaults/ServiceDefaults.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsAspireSharedProject>true</IsAspireSharedProject>
</PropertyGroup>

<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />

<PackageReference Include="Microsoft.Extensions.Http.Resilience" Version="9.4.0" />
<PackageReference Include="Microsoft.Extensions.ServiceDiscovery" Version="9.3.1" />
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.12.0" />
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.12.0" />
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.12.0" />
<PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.12.0" />
<PackageReference Include="OpenTelemetry.Instrumentation.Runtime" Version="1.12.0" />
</ItemGroup>

</Project>
25 changes: 25 additions & 0 deletions BFF/v4/MultiFrontend/ServiceDefaults/ServiceDiscovery.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (c) Duende Software. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

namespace Microsoft.Extensions.Hosting;

public static class ServiceDiscovery
{
public static Uri ResolveService(string serviceName, string appName = "https")
{
var host = serviceName;

// Compose the environment variable key
var envVarKey = $"services__{host}__{appName}__0";

// Try to get the value from environment variables
var value = Environment.GetEnvironmentVariable(envVarKey);

if (string.IsNullOrEmpty(value))
{
throw new InvalidOperationException($"Service endpoint for '{serviceName}' not found in environment variable '{envVarKey}'.");
}

return new Uri(value);
}
}
44 changes: 44 additions & 0 deletions BFF/v4/MultiFrontend/api/ApiProgram.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
builder.Services.AddOpenApi();
builder.AddServiceDefaults();

var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.MapOpenApi();
}

app.UseHttpsRedirection();

var summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};

app.MapGet("/", () => "ok");

app.MapGet("/weatherforecast", () =>
{
var forecast = Enumerable.Range(1, 5).Select(index =>
new WeatherForecast
(
DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
Random.Shared.Next(-20, 55),
summaries[Random.Shared.Next(summaries.Length)]
))
.ToArray();
return forecast;
})
.WithName("GetWeatherForecast");

app.Run();

record WeatherForecast(DateOnly Date, int TemperatureC, string? Summary)
{
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
}
Loading
Loading