Skip to content

Commit

Permalink
docs: Add NeverEnds example
Browse files Browse the repository at this point in the history
  • Loading branch information
NikiforovAll committed Jun 25, 2024
1 parent 4154c34 commit 3b2ba43
Show file tree
Hide file tree
Showing 32 changed files with 661 additions and 34 deletions.
11 changes: 11 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@
"cwd": "${workspaceFolder}/samples/Todo/AppHost",
"stopAtEntry": false,
"console": "externalTerminal"
},
{
"name": "Debug NeverEnds:AppHost",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/samples/NeverEnds/AppHost/bin/Debug/net8.0/AppHost.dll",
"args": [],
"cwd": "${workspaceFolder}/samples/NeverEnds/AppHost",
"stopAtEntry": false,
"console": "externalTerminal"
}
]
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ builder.Build().Run();

`dotnet cake --target test`

`dotnet --target pack`
`dotnet cake --target pack`

## References

Expand Down
7 changes: 7 additions & 0 deletions aspire-depends-on.sln
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nall.Aspire.Hosting.Depends
EndProject
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}"
EndProject
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}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -55,6 +57,10 @@ Global
{9CACCDF6-1C8E-4A72-89AE-523C95E5C259}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9CACCDF6-1C8E-4A72-89AE-523C95E5C259}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9CACCDF6-1C8E-4A72-89AE-523C95E5C259}.Release|Any CPU.Build.0 = Release|Any CPU
{1FD72D98-FF40-4DE2-A90A-EE396980B485}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1FD72D98-FF40-4DE2-A90A-EE396980B485}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1FD72D98-FF40-4DE2-A90A-EE396980B485}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1FD72D98-FF40-4DE2-A90A-EE396980B485}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -67,5 +73,6 @@ Global
{238E3532-D201-44F8-A131-893713EA4ED5} = {CAB6ABE8-92F5-44BC-A76F-E1342390F111}
{0ADC7AA8-32D3-42FB-AC73-207E9C886675} = {CAB6ABE8-92F5-44BC-A76F-E1342390F111}
{9CACCDF6-1C8E-4A72-89AE-523C95E5C259} = {CAB6ABE8-92F5-44BC-A76F-E1342390F111}
{1FD72D98-FF40-4DE2-A90A-EE396980B485} = {2957F7CC-E3D5-45EC-AD01-E5B90109C102}
EndGlobalSection
EndGlobal
17 changes: 17 additions & 0 deletions samples/NeverEnds/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# EditorConfig is awesome: https://EditorConfig.org

# top-most EditorConfig file
root = false
[*.cs]

# CS1591: Missing XML comment for publicly visible type or member
dotnet_diagnostic.CS1591.severity = suggestion

# IDE0058: Expression value is never used
dotnet_diagnostic.IDE0058.severity = suggestion

# IDE0053: Use expression body for lambda expression
dotnet_diagnostic.IDE0053.severity = suggestion

# CA1303: Do not pass literals as localized parameters
dotnet_diagnostic.CA1303.severity = silent
41 changes: 41 additions & 0 deletions samples/NeverEnds/AppHost/AppHost.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsAspireHost>true</IsAspireHost>
<UserSecretsId>1782dd51-972e-4551-9599-7612b341f347</UserSecretsId>
<RootNamespace>NeverEnds</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Aspire.Hosting.AppHost" />
<PackageReference Include="Aspire.Hosting.Redis" />
<PackageReference Include="Aspire.Hosting.PostgreSQL" />
<PackageReference Include="Aspire.Hosting.SqlServer" />
<PackageReference Include="Aspire.Hosting.RabbitMQ" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\WebApplication1\WebApplication1.csproj" />
<ProjectReference Include="..\WebApplication2\WebApplication2.csproj" />
<ProjectReference Include="..\..\..\src\Nall.Aspire.Hosting.DependsOn.All\Nall.Aspire.Hosting.DependsOn.All.csproj" IsAspireProjectResource="false" />
</ItemGroup>

<ItemGroup>
<Using Include="Microsoft.Extensions.Configuration" />
<Using Include="Microsoft.Extensions.DependencyInjection" />
</ItemGroup>

<ItemGroup>
<None Include="appsettings.Development.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="appsettings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
15 changes: 15 additions & 0 deletions samples/NeverEnds/AppHost/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
var builder = DistributedApplication.CreateBuilder(args);

builder.Services.Configure<DependsOnOptions>(
builder.Configuration.GetRequiredSection("DependsOnOptions")
);

var api0 = builder
.AddProject<Projects.WebApplication2>("api0")
.WithHealthCheck();

builder
.AddProject<Projects.WebApplication1>("api")
.WaitFor(api0);

builder.Build().Run();
29 changes: 29 additions & 0 deletions samples/NeverEnds/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": true,
"applicationUrl": "https://localhost:17054;http://localhost:15173",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"DOTNET_ENVIRONMENT": "Development",
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "https://localhost:21160",
"DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "https://localhost:22080"
}
},
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "http://localhost:15173",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"DOTNET_ENVIRONMENT": "Development",
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:19022",
"DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "http://localhost:20008"
}
}
}
}
21 changes: 21 additions & 0 deletions samples/NeverEnds/AppHost/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning",
"Aspire.Hosting": "Debug",
"Nall.Aspire": "Debug"
}
},
"DependsOnOptions": {
"Retry": {
"MaxRetryAttempts": 10,
"BackoffType": 1,
"Delay": "00:00:5",
"MaxDelay": "00:00:10"
},
"Timeout": {
"Timeout": "00:00:15"
}
}
}
9 changes: 9 additions & 0 deletions samples/NeverEnds/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"
}
}
}
27 changes: 27 additions & 0 deletions samples/NeverEnds/Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<Project>
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
<CentralPackageTransitivePinningEnabled>false</CentralPackageTransitivePinningEnabled>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="Aspire.Hosting.AppHost" Version="8.0.1" />
<PackageVersion Include="Aspire.Hosting.PostgreSQL" Version="8.0.1" />
<PackageVersion Include="Aspire.Hosting.RabbitMQ" Version="8.0.1" />
<PackageVersion Include="Aspire.Hosting.Redis" Version="8.0.1" />
<PackageVersion Include="Aspire.Hosting.SqlServer" Version="8.0.1" />
<PackageVersion Include="Aspire.Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.1" />
<PackageVersion Include="Aspire.Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.1" />
<PackageVersion Include="Microsoft.Extensions.Http.Resilience" Version="8.3.0" />
<PackageVersion Include="Microsoft.Extensions.ServiceDiscovery" Version="8.0.1" />
<PackageVersion Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.8.0" />
<PackageVersion Include="OpenTelemetry.Extensions.Hosting" Version="1.8.0" />
<PackageVersion Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.8.1" />
<PackageVersion Include="OpenTelemetry.Instrumentation.Http" Version="1.8.1" />
<PackageVersion Include="OpenTelemetry.Instrumentation.Runtime" Version="1.8.0" />
</ItemGroup>

<ItemGroup Label="Redundant">
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="8.0.0" />
<PackageVersion Include="MinVer" Version="5.0.0" />
</ItemGroup>
</Project>
40 changes: 40 additions & 0 deletions samples/NeverEnds/NeverEnds.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@

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}") = "ServiceDefaults", "ServiceDefaults\ServiceDefaults.csproj", "{AF8A4ED9-06C4-452D-AEAA-618EF254AD24}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AppHost", "AppHost\AppHost.csproj", "{FF4B7FB8-9AF9-4130-8969-A955CC9DB642}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebApplication1", "WebApplication1\WebApplication1.csproj", "{98FE5FA9-5F02-46D8-A269-5C373DC72AA0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebApplication2", "WebApplication2\WebApplication2.csproj", "{07CE898D-0F4C-4DCB-9650-4E7F3CC0C615}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{AF8A4ED9-06C4-452D-AEAA-618EF254AD24}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AF8A4ED9-06C4-452D-AEAA-618EF254AD24}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AF8A4ED9-06C4-452D-AEAA-618EF254AD24}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AF8A4ED9-06C4-452D-AEAA-618EF254AD24}.Release|Any CPU.Build.0 = Release|Any CPU
{FF4B7FB8-9AF9-4130-8969-A955CC9DB642}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FF4B7FB8-9AF9-4130-8969-A955CC9DB642}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FF4B7FB8-9AF9-4130-8969-A955CC9DB642}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FF4B7FB8-9AF9-4130-8969-A955CC9DB642}.Release|Any CPU.Build.0 = Release|Any CPU
{98FE5FA9-5F02-46D8-A269-5C373DC72AA0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{98FE5FA9-5F02-46D8-A269-5C373DC72AA0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{98FE5FA9-5F02-46D8-A269-5C373DC72AA0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{98FE5FA9-5F02-46D8-A269-5C373DC72AA0}.Release|Any CPU.Build.0 = Release|Any CPU
{07CE898D-0F4C-4DCB-9650-4E7F3CC0C615}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{07CE898D-0F4C-4DCB-9650-4E7F3CC0C615}.Debug|Any CPU.Build.0 = Debug|Any CPU
{07CE898D-0F4C-4DCB-9650-4E7F3CC0C615}.Release|Any CPU.ActiveCfg = Release|Any CPU
{07CE898D-0F4C-4DCB-9650-4E7F3CC0C615}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
113 changes: 113 additions & 0 deletions samples/NeverEnds/ServiceDefaults/Extensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
namespace Microsoft.Extensions.Hosting;

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

public static class Extensions
{
public static IHostApplicationBuilder AddServiceDefaults(
this IHostApplicationBuilder builder
)
{
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();
});

return builder;
}

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

builder
.Services.AddOpenTelemetry()
.WithMetrics(metrics =>
{
metrics
.AddAspNetCoreInstrumentation()
.AddHttpClientInstrumentation()
.AddRuntimeInstrumentation();
})
.WithTracing(tracing =>
{
tracing
.AddAspNetCoreInstrumentation()
// Uncomment the following line to enable gRPC instrumentation (requires the OpenTelemetry.Instrumentation.GrpcNetClient package)
//.AddGrpcClientInstrumentation()
.AddHttpClientInstrumentation();
});

builder.AddOpenTelemetryExporters();

return builder;
}

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

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

return builder;
}

public static IHostApplicationBuilder AddDefaultHealthChecks(
this IHostApplicationBuilder builder
)
{
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)
{
if (app.Environment.IsDevelopment())
{
// All health checks must pass for app to be considered ready to accept traffic after starting
app.MapHealthChecks("/health");

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

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

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

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

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

</Project>
Loading

0 comments on commit 3b2ba43

Please sign in to comment.