Skip to content

Commit 79a5a23

Browse files
committed
Adding Aspire and updating packages
1 parent aa141fd commit 79a5a23

File tree

13 files changed

+272
-9
lines changed

13 files changed

+272
-9
lines changed

sample/Directory.Packages.props

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,31 @@
55
<PackageVersion Include="Ardalis.ListStartupServices" Version="1.1.4" />
66
<PackageVersion Include="Ardalis.Result" Version="10.1.0" />
77
<PackageVersion Include="Ardalis.Result.AspNetCore" Version="10.1.0" />
8+
<PackageVersion Include="Ardalis.SharedKernel" Version="2.1.1" />
89
<PackageVersion Include="Ardalis.SmartEnum" Version="8.1.0" />
910
<PackageVersion Include="Ardalis.Specification" Version="8.0.0" />
1011
<PackageVersion Include="Ardalis.Specification.EntityFrameworkCore" Version="8.0.0" />
12+
<PackageVersion Include="Azure.Identity" Version="1.13.1" />
1113
<PackageVersion Include="coverlet.collector" Version="6.0.2" />
1214
<PackageVersion Include="FastEndpoints" Version="5.31.0" />
13-
<PackageVersion Include="FastEndpoints.ApiExplorer" Version="2.3.0" />
15+
<PackageVersion Include="FastEndpoints.ApiExplorer" Version="2.2.0" />
1416
<PackageVersion Include="FastEndpoints.Swagger" Version="5.31.0" />
15-
<PackageVersion Include="FastEndpoints.Swagger.Swashbuckle" Version="2.3.0" />
17+
<PackageVersion Include="FastEndpoints.Swagger.Swashbuckle" Version="2.2.0" />
1618
<PackageVersion Include="FluentAssertions" Version="6.12.2" />
1719
<PackageVersion Include="MailKit" Version="4.8.0" />
1820
<PackageVersion Include="MediatR" Version="12.4.1" />
19-
<PackageVersion Include="MediatR.Extensions.Autofac.DependencyInjection" Version="12.2.0" />
2021
<PackageVersion Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="9.0.0" />
2122
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="9.0.0" />
2223
<PackageVersion Include="Microsoft.EntityFrameworkCore.InMemory" Version="9.0.0" />
2324
<PackageVersion Include="Microsoft.EntityFrameworkCore.Relational" Version="9.0.0" />
25+
<PackageVersion Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.0" />
2426
<PackageVersion Include="Microsoft.EntityFrameworkCore.Tools" Version="9.0.0" />
2527
<PackageVersion Include="Microsoft.EntityFrameworkCore.Sqlite" Version="9.0.0" />
2628
<PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.0" />
29+
<PackageVersion Include="Microsoft.Extensions.Configuration" Version="9.0.0" />
30+
<PackageVersion Include="Microsoft.Extensions.Logging" Version="9.0.0" />
2731
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.0" />
32+
<PackageVersion Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="9.0.0" />
2833
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
2934
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
3035
<PackageVersion Include="NimblePros.SharedKernel" Version="2.1.1" />
@@ -38,6 +43,15 @@
3843
<PackageVersion Include="Testcontainers" Version="4.0.0" />
3944
<PackageVersion Include="Vogen" Version="5.0.3" />
4045
<PackageVersion Include="xunit" Version="2.9.2" />
41-
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.2" />
46+
<PackageVersion Include="xunit.runner.visualstudio" Version="3.0.0-pre.49" />
47+
<PackageVersion Include="Aspire.Hosting.AppHost" Version="9.0.0" />
48+
<PackageVersion Include="Microsoft.Extensions.Http.Resilience" Version="9.0.0" />
49+
<PackageVersion Include="Microsoft.Extensions.ServiceDiscovery" Version="9.0.0" />
50+
<PackageVersion Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.10.0" />
51+
<PackageVersion Include="OpenTelemetry.Extensions.Hosting" Version="1.10.0" />
52+
<PackageVersion Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.9.0" />
53+
<PackageVersion Include="OpenTelemetry.Instrumentation.Http" Version="1.9.0" />
54+
<PackageVersion Include="OpenTelemetry.Instrumentation.Runtime" Version="1.9.0" />
55+
<PackageVersion Include="Aspire.Hosting.Testing" Version="9.0.0" />
4256
</ItemGroup>
4357
</Project>

sample/NimblePros.SampleToDo.sln

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NimblePros.SampleToDo.UnitT
3535
EndProject
3636
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NimblePros.SampleToDo.UseCases", "src\NimblePros.SampleToDo.UseCases\NimblePros.SampleToDo.UseCases.csproj", "{B74A78FF-B79E-4C38-A9C7-084A90990CAD}"
3737
EndProject
38+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NimblePros.SampleToDo.AspireHost", "src\NimblePros.SampleToDo.AspireHost\NimblePros.SampleToDo.AspireHost.csproj", "{A386838E-3D47-0E25-E489-902B7426F983}"
39+
EndProject
40+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NimblePros.SampleToDo.ServiceDefaults", "src\NimblePros.SampleToDo.ServiceDefaults\NimblePros.SampleToDo.ServiceDefaults.csproj", "{6EFB0B52-15DF-2406-DA11-569E9010FD25}"
41+
EndProject
3842
Global
3943
GlobalSection(SolutionConfigurationPlatforms) = preSolution
4044
Debug|Any CPU = Debug|Any CPU
@@ -129,6 +133,30 @@ Global
129133
{B74A78FF-B79E-4C38-A9C7-084A90990CAD}.Release|x64.Build.0 = Release|Any CPU
130134
{B74A78FF-B79E-4C38-A9C7-084A90990CAD}.Release|x86.ActiveCfg = Release|Any CPU
131135
{B74A78FF-B79E-4C38-A9C7-084A90990CAD}.Release|x86.Build.0 = Release|Any CPU
136+
{A386838E-3D47-0E25-E489-902B7426F983}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
137+
{A386838E-3D47-0E25-E489-902B7426F983}.Debug|Any CPU.Build.0 = Debug|Any CPU
138+
{A386838E-3D47-0E25-E489-902B7426F983}.Debug|x64.ActiveCfg = Debug|Any CPU
139+
{A386838E-3D47-0E25-E489-902B7426F983}.Debug|x64.Build.0 = Debug|Any CPU
140+
{A386838E-3D47-0E25-E489-902B7426F983}.Debug|x86.ActiveCfg = Debug|Any CPU
141+
{A386838E-3D47-0E25-E489-902B7426F983}.Debug|x86.Build.0 = Debug|Any CPU
142+
{A386838E-3D47-0E25-E489-902B7426F983}.Release|Any CPU.ActiveCfg = Release|Any CPU
143+
{A386838E-3D47-0E25-E489-902B7426F983}.Release|Any CPU.Build.0 = Release|Any CPU
144+
{A386838E-3D47-0E25-E489-902B7426F983}.Release|x64.ActiveCfg = Release|Any CPU
145+
{A386838E-3D47-0E25-E489-902B7426F983}.Release|x64.Build.0 = Release|Any CPU
146+
{A386838E-3D47-0E25-E489-902B7426F983}.Release|x86.ActiveCfg = Release|Any CPU
147+
{A386838E-3D47-0E25-E489-902B7426F983}.Release|x86.Build.0 = Release|Any CPU
148+
{6EFB0B52-15DF-2406-DA11-569E9010FD25}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
149+
{6EFB0B52-15DF-2406-DA11-569E9010FD25}.Debug|Any CPU.Build.0 = Debug|Any CPU
150+
{6EFB0B52-15DF-2406-DA11-569E9010FD25}.Debug|x64.ActiveCfg = Debug|Any CPU
151+
{6EFB0B52-15DF-2406-DA11-569E9010FD25}.Debug|x64.Build.0 = Debug|Any CPU
152+
{6EFB0B52-15DF-2406-DA11-569E9010FD25}.Debug|x86.ActiveCfg = Debug|Any CPU
153+
{6EFB0B52-15DF-2406-DA11-569E9010FD25}.Debug|x86.Build.0 = Debug|Any CPU
154+
{6EFB0B52-15DF-2406-DA11-569E9010FD25}.Release|Any CPU.ActiveCfg = Release|Any CPU
155+
{6EFB0B52-15DF-2406-DA11-569E9010FD25}.Release|Any CPU.Build.0 = Release|Any CPU
156+
{6EFB0B52-15DF-2406-DA11-569E9010FD25}.Release|x64.ActiveCfg = Release|Any CPU
157+
{6EFB0B52-15DF-2406-DA11-569E9010FD25}.Release|x64.Build.0 = Release|Any CPU
158+
{6EFB0B52-15DF-2406-DA11-569E9010FD25}.Release|x86.ActiveCfg = Release|Any CPU
159+
{6EFB0B52-15DF-2406-DA11-569E9010FD25}.Release|x86.Build.0 = Release|Any CPU
132160
EndGlobalSection
133161
GlobalSection(SolutionProperties) = preSolution
134162
HideSolutionNode = FALSE
@@ -141,6 +169,8 @@ Global
141169
{0776DC14-9000-47A4-A3F4-ECBCF8CEBC17} = {B31B4797-1D9F-4288-808C-BE9A31A98C7D}
142170
{1DC7F5A0-DDF7-4975-84EB-05F4FC1B6AB5} = {B31B4797-1D9F-4288-808C-BE9A31A98C7D}
143171
{B74A78FF-B79E-4C38-A9C7-084A90990CAD} = {106AE906-5075-410A-B941-912F811848EE}
172+
{A386838E-3D47-0E25-E489-902B7426F983} = {106AE906-5075-410A-B941-912F811848EE}
173+
{6EFB0B52-15DF-2406-DA11-569E9010FD25} = {106AE906-5075-410A-B941-912F811848EE}
144174
EndGlobalSection
145175
GlobalSection(ExtensibilityGlobals) = postSolution
146176
SolutionGuid = {B0F19343-8185-4A9F-9165-0EA8544BC925}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<Sdk Name="Aspire.AppHost.Sdk" Version="9.0.0" />
4+
5+
<PropertyGroup>
6+
<OutputType>Exe</OutputType>
7+
<TargetFramework>net9.0</TargetFramework>
8+
<ImplicitUsings>enable</ImplicitUsings>
9+
<Nullable>enable</Nullable>
10+
<IsAspireHost>true</IsAspireHost>
11+
<UserSecretsId>c540eeb6-e06b-4456-a539-be58dd8b88c7</UserSecretsId>
12+
</PropertyGroup>
13+
14+
<ItemGroup>
15+
<PackageReference Include="Aspire.Hosting.AppHost" />
16+
</ItemGroup>
17+
18+
<ItemGroup>
19+
<ProjectReference Include="..\NimblePros.SampleToDo.Web\NimblePros.SampleToDo.Web.csproj" />
20+
</ItemGroup>
21+
<ItemGroup>
22+
<!-- The IsAspireProjectResource attribute tells .NET Aspire to treat this
23+
reference as a standard project reference and not attempt to generate
24+
a metadata file -->
25+
<ProjectReference Include="..\NimblePros.SampleToDo.ServiceDefaults\NimblePros.SampleToDo.ServiceDefaults.csproj"
26+
IsAspireProjectResource="false" />
27+
</ItemGroup>
28+
29+
</Project>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
var builder = DistributedApplication.CreateBuilder(args);
2+
3+
builder.AddProject<Projects.NimblePros_SampleToDo_Web>("web");
4+
5+
builder.Build().Run();
Lines changed: 29 additions & 0 deletions
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:17143;http://localhost:15258",
9+
"environmentVariables": {
10+
"ASPNETCORE_ENVIRONMENT": "Development",
11+
"DOTNET_ENVIRONMENT": "Development",
12+
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "https://localhost:21007",
13+
"DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "https://localhost:22245"
14+
}
15+
},
16+
"http": {
17+
"commandName": "Project",
18+
"dotnetRunMessages": true,
19+
"launchBrowser": true,
20+
"applicationUrl": "http://localhost:15258",
21+
"environmentVariables": {
22+
"ASPNETCORE_ENVIRONMENT": "Development",
23+
"DOTNET_ENVIRONMENT": "Development",
24+
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:19187",
25+
"DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "http://localhost:20134"
26+
}
27+
}
28+
}
29+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft.AspNetCore": "Warning"
6+
}
7+
}
8+
}
Lines changed: 9 additions & 0 deletions
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+
}

sample/src/NimblePros.SampleToDo.Core/ProjectAggregate/ToDoItem.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using NimblePros.SampleToDo.Core.ProjectAggregate.Events;
2-
using Ardalis.SharedKernel;
32

43
namespace NimblePros.SampleToDo.Core.ProjectAggregate;
54

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
using Microsoft.AspNetCore.Builder;
2+
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
3+
using Microsoft.Extensions.DependencyInjection;
4+
using Microsoft.Extensions.Diagnostics.HealthChecks;
5+
using Microsoft.Extensions.Logging;
6+
using Microsoft.Extensions.ServiceDiscovery;
7+
using OpenTelemetry;
8+
using OpenTelemetry.Metrics;
9+
using OpenTelemetry.Trace;
10+
11+
namespace Microsoft.Extensions.Hosting;
12+
13+
// Adds common .NET Aspire services: service discovery, resilience, health checks, and OpenTelemetry.
14+
// This project should be referenced by each service project in your solution.
15+
// To learn more about using this project, see https://aka.ms/dotnet/aspire/service-defaults
16+
public static class Extensions
17+
{
18+
public static TBuilder AddServiceDefaults<TBuilder>(this TBuilder builder) where TBuilder : IHostApplicationBuilder
19+
{
20+
builder.ConfigureOpenTelemetry();
21+
22+
builder.AddDefaultHealthChecks();
23+
24+
builder.Services.AddServiceDiscovery();
25+
26+
builder.Services.ConfigureHttpClientDefaults(http =>
27+
{
28+
// Turn on resilience by default
29+
http.AddStandardResilienceHandler();
30+
31+
// Turn on service discovery by default
32+
http.AddServiceDiscovery();
33+
});
34+
35+
// Uncomment the following to restrict the allowed schemes for service discovery.
36+
// builder.Services.Configure<ServiceDiscoveryOptions>(options =>
37+
// {
38+
// options.AllowedSchemes = ["https"];
39+
// });
40+
41+
return builder;
42+
}
43+
44+
public static TBuilder ConfigureOpenTelemetry<TBuilder>(this TBuilder builder) where TBuilder : IHostApplicationBuilder
45+
{
46+
builder.Logging.AddOpenTelemetry(logging =>
47+
{
48+
logging.IncludeFormattedMessage = true;
49+
logging.IncludeScopes = true;
50+
});
51+
52+
builder.Services.AddOpenTelemetry()
53+
.WithMetrics(metrics =>
54+
{
55+
metrics.AddAspNetCoreInstrumentation()
56+
.AddHttpClientInstrumentation()
57+
.AddRuntimeInstrumentation();
58+
})
59+
.WithTracing(tracing =>
60+
{
61+
tracing.AddAspNetCoreInstrumentation()
62+
// Uncomment the following line to enable gRPC instrumentation (requires the OpenTelemetry.Instrumentation.GrpcNetClient package)
63+
//.AddGrpcClientInstrumentation()
64+
.AddHttpClientInstrumentation();
65+
});
66+
67+
builder.AddOpenTelemetryExporters();
68+
69+
return builder;
70+
}
71+
72+
private static TBuilder AddOpenTelemetryExporters<TBuilder>(this TBuilder builder) where TBuilder : IHostApplicationBuilder
73+
{
74+
var useOtlpExporter = !string.IsNullOrWhiteSpace(builder.Configuration["OTEL_EXPORTER_OTLP_ENDPOINT"]);
75+
76+
if (useOtlpExporter)
77+
{
78+
builder.Services.AddOpenTelemetry().UseOtlpExporter();
79+
}
80+
81+
// Uncomment the following lines to enable the Azure Monitor exporter (requires the Azure.Monitor.OpenTelemetry.AspNetCore package)
82+
//if (!string.IsNullOrEmpty(builder.Configuration["APPLICATIONINSIGHTS_CONNECTION_STRING"]))
83+
//{
84+
// builder.Services.AddOpenTelemetry()
85+
// .UseAzureMonitor();
86+
//}
87+
88+
return builder;
89+
}
90+
91+
public static TBuilder AddDefaultHealthChecks<TBuilder>(this TBuilder builder) where TBuilder : IHostApplicationBuilder
92+
{
93+
builder.Services.AddHealthChecks()
94+
// Add a default liveness check to ensure app is responsive
95+
.AddCheck("self", () => HealthCheckResult.Healthy(), ["live"]);
96+
97+
return builder;
98+
}
99+
100+
public static WebApplication MapDefaultEndpoints(this WebApplication app)
101+
{
102+
// Adding health checks endpoints to applications in non-development environments has security implications.
103+
// See https://aka.ms/dotnet/aspire/healthchecks for details before enabling these endpoints in non-development environments.
104+
if (app.Environment.IsDevelopment())
105+
{
106+
// All health checks must pass for app to be considered ready to accept traffic after starting
107+
app.MapHealthChecks("/health");
108+
109+
// Only health checks tagged with the "live" tag must pass for app to be considered alive
110+
app.MapHealthChecks("/alive", new HealthCheckOptions
111+
{
112+
Predicate = r => r.Tags.Contains("live")
113+
});
114+
}
115+
116+
return app;
117+
}
118+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<ImplicitUsings>enable</ImplicitUsings>
5+
<Nullable>enable</Nullable>
6+
<IsAspireSharedProject>true</IsAspireSharedProject>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<FrameworkReference Include="Microsoft.AspNetCore.App" />
11+
12+
<PackageReference Include="Microsoft.Extensions.Http.Resilience" />
13+
<PackageReference Include="Microsoft.Extensions.ServiceDiscovery" />
14+
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" />
15+
<PackageReference Include="OpenTelemetry.Extensions.Hosting" />
16+
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" />
17+
<PackageReference Include="OpenTelemetry.Instrumentation.Http" />
18+
<PackageReference Include="OpenTelemetry.Instrumentation.Runtime" />
19+
</ItemGroup>
20+
21+
</Project>

0 commit comments

Comments
 (0)