Skip to content
This repository was archived by the owner on Feb 2, 2025. It is now read-only.

Commit 3b2ba43

Browse files
committed
docs: Add NeverEnds example
1 parent 4154c34 commit 3b2ba43

32 files changed

+661
-34
lines changed

.vscode/launch.json

+11
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,17 @@
2222
"cwd": "${workspaceFolder}/samples/Todo/AppHost",
2323
"stopAtEntry": false,
2424
"console": "externalTerminal"
25+
},
26+
{
27+
"name": "Debug NeverEnds:AppHost",
28+
"type": "coreclr",
29+
"request": "launch",
30+
"preLaunchTask": "build",
31+
"program": "${workspaceFolder}/samples/NeverEnds/AppHost/bin/Debug/net8.0/AppHost.dll",
32+
"args": [],
33+
"cwd": "${workspaceFolder}/samples/NeverEnds/AppHost",
34+
"stopAtEntry": false,
35+
"console": "externalTerminal"
2536
}
2637
]
2738
}

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ builder.Build().Run();
6161

6262
`dotnet cake --target test`
6363

64-
`dotnet --target pack`
64+
`dotnet cake --target pack`
6565

6666
## References
6767

aspire-depends-on.sln

+7
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nall.Aspire.Hosting.Depends
2121
EndProject
2222
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nall.Aspire.Hosting.DependsOn.Uris", "src\Nall.Aspire.Hosting.DependsOn.Uris\Nall.Aspire.Hosting.DependsOn.Uris.csproj", "{9CACCDF6-1C8E-4A72-89AE-523C95E5C259}"
2323
EndProject
24+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nall.Aspire.Hosting.DependsOn.NeverEnds.IntegrationTesting", "tests\Nall.Aspire.Hosting.DependsOn.NeverEnds.IntegrationTesting\Nall.Aspire.Hosting.DependsOn.NeverEnds.IntegrationTesting.csproj", "{1FD72D98-FF40-4DE2-A90A-EE396980B485}"
25+
EndProject
2426
Global
2527
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2628
Debug|Any CPU = Debug|Any CPU
@@ -55,6 +57,10 @@ Global
5557
{9CACCDF6-1C8E-4A72-89AE-523C95E5C259}.Debug|Any CPU.Build.0 = Debug|Any CPU
5658
{9CACCDF6-1C8E-4A72-89AE-523C95E5C259}.Release|Any CPU.ActiveCfg = Release|Any CPU
5759
{9CACCDF6-1C8E-4A72-89AE-523C95E5C259}.Release|Any CPU.Build.0 = Release|Any CPU
60+
{1FD72D98-FF40-4DE2-A90A-EE396980B485}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
61+
{1FD72D98-FF40-4DE2-A90A-EE396980B485}.Debug|Any CPU.Build.0 = Debug|Any CPU
62+
{1FD72D98-FF40-4DE2-A90A-EE396980B485}.Release|Any CPU.ActiveCfg = Release|Any CPU
63+
{1FD72D98-FF40-4DE2-A90A-EE396980B485}.Release|Any CPU.Build.0 = Release|Any CPU
5864
EndGlobalSection
5965
GlobalSection(SolutionProperties) = preSolution
6066
HideSolutionNode = FALSE
@@ -67,5 +73,6 @@ Global
6773
{238E3532-D201-44F8-A131-893713EA4ED5} = {CAB6ABE8-92F5-44BC-A76F-E1342390F111}
6874
{0ADC7AA8-32D3-42FB-AC73-207E9C886675} = {CAB6ABE8-92F5-44BC-A76F-E1342390F111}
6975
{9CACCDF6-1C8E-4A72-89AE-523C95E5C259} = {CAB6ABE8-92F5-44BC-A76F-E1342390F111}
76+
{1FD72D98-FF40-4DE2-A90A-EE396980B485} = {2957F7CC-E3D5-45EC-AD01-E5B90109C102}
7077
EndGlobalSection
7178
EndGlobal

samples/NeverEnds/.editorconfig

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# EditorConfig is awesome: https://EditorConfig.org
2+
3+
# top-most EditorConfig file
4+
root = false
5+
[*.cs]
6+
7+
# CS1591: Missing XML comment for publicly visible type or member
8+
dotnet_diagnostic.CS1591.severity = suggestion
9+
10+
# IDE0058: Expression value is never used
11+
dotnet_diagnostic.IDE0058.severity = suggestion
12+
13+
# IDE0053: Use expression body for lambda expression
14+
dotnet_diagnostic.IDE0053.severity = suggestion
15+
16+
# CA1303: Do not pass literals as localized parameters
17+
dotnet_diagnostic.CA1303.severity = silent
+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
<IsAspireHost>true</IsAspireHost>
9+
<UserSecretsId>1782dd51-972e-4551-9599-7612b341f347</UserSecretsId>
10+
<RootNamespace>NeverEnds</RootNamespace>
11+
</PropertyGroup>
12+
13+
<ItemGroup>
14+
<PackageReference Include="Aspire.Hosting.AppHost" />
15+
<PackageReference Include="Aspire.Hosting.Redis" />
16+
<PackageReference Include="Aspire.Hosting.PostgreSQL" />
17+
<PackageReference Include="Aspire.Hosting.SqlServer" />
18+
<PackageReference Include="Aspire.Hosting.RabbitMQ" />
19+
</ItemGroup>
20+
21+
<ItemGroup>
22+
<ProjectReference Include="..\WebApplication1\WebApplication1.csproj" />
23+
<ProjectReference Include="..\WebApplication2\WebApplication2.csproj" />
24+
<ProjectReference Include="..\..\..\src\Nall.Aspire.Hosting.DependsOn.All\Nall.Aspire.Hosting.DependsOn.All.csproj" IsAspireProjectResource="false" />
25+
</ItemGroup>
26+
27+
<ItemGroup>
28+
<Using Include="Microsoft.Extensions.Configuration" />
29+
<Using Include="Microsoft.Extensions.DependencyInjection" />
30+
</ItemGroup>
31+
32+
<ItemGroup>
33+
<None Include="appsettings.Development.json">
34+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
35+
</None>
36+
<None Include="appsettings.json">
37+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
38+
</None>
39+
</ItemGroup>
40+
41+
</Project>

samples/NeverEnds/AppHost/Program.cs

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
var builder = DistributedApplication.CreateBuilder(args);
2+
3+
builder.Services.Configure<DependsOnOptions>(
4+
builder.Configuration.GetRequiredSection("DependsOnOptions")
5+
);
6+
7+
var api0 = builder
8+
.AddProject<Projects.WebApplication2>("api0")
9+
.WithHealthCheck();
10+
11+
builder
12+
.AddProject<Projects.WebApplication1>("api")
13+
.WaitFor(api0);
14+
15+
builder.Build().Run();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"$schema": "https://json.schemastore.org/launchsettings.json",
3+
"profiles": {
4+
"https": {
5+
"commandName": "Project",
6+
"dotnetRunMessages": true,
7+
"launchBrowser": true,
8+
"applicationUrl": "https://localhost:17054;http://localhost:15173",
9+
"environmentVariables": {
10+
"ASPNETCORE_ENVIRONMENT": "Development",
11+
"DOTNET_ENVIRONMENT": "Development",
12+
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "https://localhost:21160",
13+
"DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "https://localhost:22080"
14+
}
15+
},
16+
"http": {
17+
"commandName": "Project",
18+
"dotnetRunMessages": true,
19+
"launchBrowser": true,
20+
"applicationUrl": "http://localhost:15173",
21+
"environmentVariables": {
22+
"ASPNETCORE_ENVIRONMENT": "Development",
23+
"DOTNET_ENVIRONMENT": "Development",
24+
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:19022",
25+
"DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "http://localhost:20008"
26+
}
27+
}
28+
}
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft.AspNetCore": "Warning",
6+
"Aspire.Hosting": "Debug",
7+
"Nall.Aspire": "Debug"
8+
}
9+
},
10+
"DependsOnOptions": {
11+
"Retry": {
12+
"MaxRetryAttempts": 10,
13+
"BackoffType": 1,
14+
"Delay": "00:00:5",
15+
"MaxDelay": "00:00:10"
16+
},
17+
"Timeout": {
18+
"Timeout": "00:00:15"
19+
}
20+
}
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft.AspNetCore": "Warning",
6+
"Aspire.Hosting.Dcp": "Warning"
7+
}
8+
}
9+
}
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<Project>
2+
<PropertyGroup>
3+
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
4+
<CentralPackageTransitivePinningEnabled>false</CentralPackageTransitivePinningEnabled>
5+
</PropertyGroup>
6+
<ItemGroup>
7+
<PackageVersion Include="Aspire.Hosting.AppHost" Version="8.0.1" />
8+
<PackageVersion Include="Aspire.Hosting.PostgreSQL" Version="8.0.1" />
9+
<PackageVersion Include="Aspire.Hosting.RabbitMQ" Version="8.0.1" />
10+
<PackageVersion Include="Aspire.Hosting.Redis" Version="8.0.1" />
11+
<PackageVersion Include="Aspire.Hosting.SqlServer" Version="8.0.1" />
12+
<PackageVersion Include="Aspire.Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.1" />
13+
<PackageVersion Include="Aspire.Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.1" />
14+
<PackageVersion Include="Microsoft.Extensions.Http.Resilience" Version="8.3.0" />
15+
<PackageVersion Include="Microsoft.Extensions.ServiceDiscovery" Version="8.0.1" />
16+
<PackageVersion Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.8.0" />
17+
<PackageVersion Include="OpenTelemetry.Extensions.Hosting" Version="1.8.0" />
18+
<PackageVersion Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.8.1" />
19+
<PackageVersion Include="OpenTelemetry.Instrumentation.Http" Version="1.8.1" />
20+
<PackageVersion Include="OpenTelemetry.Instrumentation.Runtime" Version="1.8.0" />
21+
</ItemGroup>
22+
23+
<ItemGroup Label="Redundant">
24+
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="8.0.0" />
25+
<PackageVersion Include="MinVer" Version="5.0.0" />
26+
</ItemGroup>
27+
</Project>

samples/NeverEnds/NeverEnds.sln

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.0.31903.59
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ServiceDefaults", "ServiceDefaults\ServiceDefaults.csproj", "{AF8A4ED9-06C4-452D-AEAA-618EF254AD24}"
7+
EndProject
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AppHost", "AppHost\AppHost.csproj", "{FF4B7FB8-9AF9-4130-8969-A955CC9DB642}"
9+
EndProject
10+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebApplication1", "WebApplication1\WebApplication1.csproj", "{98FE5FA9-5F02-46D8-A269-5C373DC72AA0}"
11+
EndProject
12+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebApplication2", "WebApplication2\WebApplication2.csproj", "{07CE898D-0F4C-4DCB-9650-4E7F3CC0C615}"
13+
EndProject
14+
Global
15+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
16+
Debug|Any CPU = Debug|Any CPU
17+
Release|Any CPU = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
23+
{AF8A4ED9-06C4-452D-AEAA-618EF254AD24}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
24+
{AF8A4ED9-06C4-452D-AEAA-618EF254AD24}.Debug|Any CPU.Build.0 = Debug|Any CPU
25+
{AF8A4ED9-06C4-452D-AEAA-618EF254AD24}.Release|Any CPU.ActiveCfg = Release|Any CPU
26+
{AF8A4ED9-06C4-452D-AEAA-618EF254AD24}.Release|Any CPU.Build.0 = Release|Any CPU
27+
{FF4B7FB8-9AF9-4130-8969-A955CC9DB642}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
28+
{FF4B7FB8-9AF9-4130-8969-A955CC9DB642}.Debug|Any CPU.Build.0 = Debug|Any CPU
29+
{FF4B7FB8-9AF9-4130-8969-A955CC9DB642}.Release|Any CPU.ActiveCfg = Release|Any CPU
30+
{FF4B7FB8-9AF9-4130-8969-A955CC9DB642}.Release|Any CPU.Build.0 = Release|Any CPU
31+
{98FE5FA9-5F02-46D8-A269-5C373DC72AA0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
32+
{98FE5FA9-5F02-46D8-A269-5C373DC72AA0}.Debug|Any CPU.Build.0 = Debug|Any CPU
33+
{98FE5FA9-5F02-46D8-A269-5C373DC72AA0}.Release|Any CPU.ActiveCfg = Release|Any CPU
34+
{98FE5FA9-5F02-46D8-A269-5C373DC72AA0}.Release|Any CPU.Build.0 = Release|Any CPU
35+
{07CE898D-0F4C-4DCB-9650-4E7F3CC0C615}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
36+
{07CE898D-0F4C-4DCB-9650-4E7F3CC0C615}.Debug|Any CPU.Build.0 = Debug|Any CPU
37+
{07CE898D-0F4C-4DCB-9650-4E7F3CC0C615}.Release|Any CPU.ActiveCfg = Release|Any CPU
38+
{07CE898D-0F4C-4DCB-9650-4E7F3CC0C615}.Release|Any CPU.Build.0 = Release|Any CPU
39+
EndGlobalSection
40+
EndGlobal
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
namespace Microsoft.Extensions.Hosting;
2+
3+
using Microsoft.AspNetCore.Builder;
4+
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
5+
using Microsoft.Extensions.DependencyInjection;
6+
using Microsoft.Extensions.Diagnostics.HealthChecks;
7+
using Microsoft.Extensions.Logging;
8+
using OpenTelemetry;
9+
using OpenTelemetry.Metrics;
10+
using OpenTelemetry.Trace;
11+
12+
public static class Extensions
13+
{
14+
public static IHostApplicationBuilder AddServiceDefaults(
15+
this IHostApplicationBuilder builder
16+
)
17+
{
18+
builder.ConfigureOpenTelemetry();
19+
20+
builder.AddDefaultHealthChecks();
21+
22+
builder.Services.AddServiceDiscovery();
23+
24+
builder.Services.ConfigureHttpClientDefaults(http =>
25+
{
26+
// Turn on resilience by default
27+
http.AddStandardResilienceHandler();
28+
29+
// Turn on service discovery by default
30+
http.AddServiceDiscovery();
31+
});
32+
33+
return builder;
34+
}
35+
36+
public static IHostApplicationBuilder ConfigureOpenTelemetry(
37+
this IHostApplicationBuilder builder
38+
)
39+
{
40+
builder.Logging.AddOpenTelemetry(logging =>
41+
{
42+
logging.IncludeFormattedMessage = true;
43+
logging.IncludeScopes = true;
44+
});
45+
46+
builder
47+
.Services.AddOpenTelemetry()
48+
.WithMetrics(metrics =>
49+
{
50+
metrics
51+
.AddAspNetCoreInstrumentation()
52+
.AddHttpClientInstrumentation()
53+
.AddRuntimeInstrumentation();
54+
})
55+
.WithTracing(tracing =>
56+
{
57+
tracing
58+
.AddAspNetCoreInstrumentation()
59+
// Uncomment the following line to enable gRPC instrumentation (requires the OpenTelemetry.Instrumentation.GrpcNetClient package)
60+
//.AddGrpcClientInstrumentation()
61+
.AddHttpClientInstrumentation();
62+
});
63+
64+
builder.AddOpenTelemetryExporters();
65+
66+
return builder;
67+
}
68+
69+
private static IHostApplicationBuilder AddOpenTelemetryExporters(
70+
this IHostApplicationBuilder builder
71+
)
72+
{
73+
var useOtlpExporter = !string.IsNullOrWhiteSpace(
74+
builder.Configuration["OTEL_EXPORTER_OTLP_ENDPOINT"]
75+
);
76+
77+
if (useOtlpExporter)
78+
{
79+
builder.Services.AddOpenTelemetry().UseOtlpExporter();
80+
}
81+
82+
return builder;
83+
}
84+
85+
public static IHostApplicationBuilder AddDefaultHealthChecks(
86+
this IHostApplicationBuilder builder
87+
)
88+
{
89+
builder
90+
.Services.AddHealthChecks()
91+
// Add a default liveness check to ensure app is responsive
92+
.AddCheck("self", () => HealthCheckResult.Healthy(), ["live"]);
93+
94+
return builder;
95+
}
96+
97+
public static WebApplication MapDefaultEndpoints(this WebApplication app)
98+
{
99+
if (app.Environment.IsDevelopment())
100+
{
101+
// All health checks must pass for app to be considered ready to accept traffic after starting
102+
app.MapHealthChecks("/health");
103+
104+
// Only health checks tagged with the "live" tag must pass for app to be considered alive
105+
app.MapHealthChecks(
106+
"/alive",
107+
new HealthCheckOptions { Predicate = r => r.Tags.Contains("live") }
108+
);
109+
}
110+
111+
return app;
112+
}
113+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
<IsAspireSharedProject>true</IsAspireSharedProject>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<FrameworkReference Include="Microsoft.AspNetCore.App" />
12+
13+
<PackageReference Include="Microsoft.Extensions.Http.Resilience" />
14+
<PackageReference Include="Microsoft.Extensions.ServiceDiscovery" />
15+
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" />
16+
<PackageReference Include="OpenTelemetry.Extensions.Hosting" />
17+
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" />
18+
<PackageReference Include="OpenTelemetry.Instrumentation.Http" />
19+
<PackageReference Include="OpenTelemetry.Instrumentation.Runtime" />
20+
</ItemGroup>
21+
22+
</Project>

0 commit comments

Comments
 (0)