Skip to content

Commit e50d00b

Browse files
authored
Updated to .NET Aspire 9.2 (#129)
1 parent ffbb72b commit e50d00b

19 files changed

+64
-61
lines changed

complete/Api/Api.csproj

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@
55
<ImplicitUsings>enable</ImplicitUsings>
66
</PropertyGroup>
77
<ItemGroup>
8-
<PackageReference Include="Aspire.StackExchange.Redis.OutputCaching" Version="9.1.0" />
9-
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.2" />
8+
<PackageReference Include="Aspire.StackExchange.Redis.OutputCaching" Version="9.2.0" />
9+
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.4" />
1010
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.4" />
11-
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.2" />
11+
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.4">
12+
<PrivateAssets>all</PrivateAssets>
13+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
14+
</PackageReference>
1215
</ItemGroup>
1316
<ItemGroup>
1417
<ProjectReference Include="..\ServiceDefaults\ServiceDefaults.csproj" />

complete/Api/Program.cs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
using OpenTelemetry.Metrics;
2-
using OpenTelemetry.Trace;
3-
using Api.Data;
4-
using Microsoft.EntityFrameworkCore;
5-
61
var builder = WebApplication.CreateBuilder(args);
72

83
builder.AddRedisOutputCache("cache");
@@ -19,16 +14,16 @@
1914
builder.Services.AddNwsManager();
2015

2116
builder.Services.AddOpenTelemetry()
22-
.WithMetrics(m => m.AddMeter("NwsManagerMetrics"))
23-
.WithTracing(m => m.AddSource("NwsManager"));
17+
.WithMetrics(m => m.AddMeter("NwsManagerMetrics"))
18+
.WithTracing(m => m.AddSource("NwsManager"));
2419

2520
var app = builder.Build();
2621

2722
app.MapDefaultEndpoints();
2823

2924
if (app.Environment.IsDevelopment())
3025
{
31-
app.MapOpenApi();
26+
app.MapOpenApi();
3227
}
3328

3429
app.UseHttpsRedirection();

complete/AppHost/AppHost.csproj

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2-
<Sdk Name="Aspire.AppHost.Sdk" Version="9.1.0" />
2+
<Sdk Name="Aspire.AppHost.Sdk" Version="9.2.0" />
33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
55
<TargetFramework>net9.0</TargetFramework>
66
<ImplicitUsings>enable</ImplicitUsings>
77
<Nullable>enable</Nullable>
8-
<IsAspireHost>true</IsAspireHost>
98
<UserSecretsId>23eb7bf1-476d-4f58-9d5c-f8369a94f289</UserSecretsId>
109
</PropertyGroup>
1110
<ItemGroup>
12-
<PackageReference Include="Aspire.Hosting.AppHost" Version="9.1.0" />
13-
<PackageReference Include="Aspire.Hosting.PostgreSQL" Version="9.1.0" />
14-
<PackageReference Include="Aspire.Hosting.Redis" Version="9.1.0" />
11+
<PackageReference Include="Aspire.Hosting.AppHost" Version="9.2.0" />
12+
<PackageReference Include="Aspire.Hosting.PostgreSQL" Version="9.2.0" />
13+
<PackageReference Include="Aspire.Hosting.Redis" Version="9.2.0" />
1514
</ItemGroup>
1615
<ItemGroup>
1716
<ProjectReference Include="..\Api\Api.csproj" />

complete/AppHost/Program.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
var builder = DistributedApplication.CreateBuilder(args);
22

33
var cache = builder.AddRedis("cache")
4-
.WithRedisCommander();
4+
.WithRedisInsight();
55

6-
var api = builder.AddProject<Projects.Api>("api")
7-
.WithReference(cache);
6+
var api = builder.AddProject<Projects.Api>("api")//;
7+
.WithReference(cache);
88

99
var postgres = builder.AddPostgres("postgres")
10-
.WithDataVolume(isReadOnly: false);
10+
.WithDataVolume(isReadOnly: false);
1111

1212
var weatherDb = postgres.AddDatabase("weatherdb");
1313

1414
var web = builder.AddProject<Projects.MyWeatherHub>("myweatherhub")
15-
.WithReference(api)
16-
.WithReference(weatherDb)
17-
.WaitFor(postgres)
18-
.WithExternalHttpEndpoints();
15+
.WithReference(api)
16+
.WithReference(weatherDb)
17+
.WaitFor(postgres)
18+
.WithExternalHttpEndpoints();
1919

2020
builder.Build().Run();

complete/IntegrationTests/IntegrationTests.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
</PropertyGroup>
1515

1616
<ItemGroup>
17-
<PackageReference Include="Aspire.Hosting.Testing" Version="9.1.0" />
18-
<PackageReference Include="MSTest" Version="3.8.2" />
17+
<PackageReference Include="Aspire.Hosting.Testing" Version="9.2.0" />
18+
<PackageReference Include="MSTest" Version="3.8.3" />
1919
</ItemGroup>
2020

2121
<ItemGroup>

complete/MyWeatherHub/MyWeatherHub.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
<ImplicitUsings>enable</ImplicitUsings>
66
</PropertyGroup>
77
<ItemGroup>
8-
<PackageReference Include="Aspire.Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.1.0" />
9-
<PackageReference Include="Microsoft.AspNetCore.Components.QuickGrid" Version="9.0.2" />
10-
<PackageReference Include="Microsoft.Extensions.ApiDescription.Client" Version="9.0.2">
8+
<PackageReference Include="Aspire.Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.2.0" />
9+
<PackageReference Include="Microsoft.AspNetCore.Components.QuickGrid" Version="9.0.4" />
10+
<PackageReference Include="Microsoft.Extensions.ApiDescription.Client" Version="9.0.4">
1111
<PrivateAssets>all</PrivateAssets>
1212
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1313
</PackageReference>

complete/MyWeatherHub/Program.cs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
builder.AddServiceDefaults();
77
builder.Services.AddHttpClient<NwsManager>(client =>
88
{
9-
client.BaseAddress = new("https+http://api");
9+
client.BaseAddress = new("https+http://api");
1010
});
1111

1212
// Add services to the container.
1313
builder.Services.AddRazorComponents()
14-
.AddInteractiveServerComponents();
14+
.AddInteractiveServerComponents();
1515

1616
builder.Services.AddMemoryCache();
1717

@@ -24,17 +24,15 @@
2424
// Configure the HTTP request pipeline.
2525
if (!app.Environment.IsDevelopment())
2626
{
27-
app.UseExceptionHandler("/Error", createScopeForErrors: true);
28-
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
29-
app.UseHsts();
27+
app.UseExceptionHandler("/Error", createScopeForErrors: true);
28+
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
29+
app.UseHsts();
3030
}
31-
else
31+
else
3232
{
33-
using (var scope = app.Services.CreateScope())
34-
{
35-
var context = scope.ServiceProvider.GetRequiredService<MyWeatherContext>();
36-
await context.Database.EnsureCreatedAsync();
37-
}
33+
using var scope = app.Services.CreateScope();
34+
var context = scope.ServiceProvider.GetRequiredService<MyWeatherContext>();
35+
await context.Database.EnsureCreatedAsync();
3836
}
3937

4038
app.UseHttpsRedirection();
@@ -43,6 +41,6 @@
4341
app.UseAntiforgery();
4442

4543
app.MapRazorComponents<App>()
46-
.AddInteractiveServerRenderMode();
44+
.AddInteractiveServerRenderMode();
4745

4846
app.Run();

complete/ServiceDefaults/ServiceDefaults.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
</PropertyGroup>
88
<ItemGroup>
99
<FrameworkReference Include="Microsoft.AspNetCore.App" />
10-
<PackageReference Include="Microsoft.Extensions.Http.Resilience" Version="9.2.0" />
11-
<PackageReference Include="Microsoft.Extensions.ServiceDiscovery" Version="9.1.0" />
10+
<PackageReference Include="Microsoft.Extensions.Http.Resilience" Version="9.4.0" />
11+
<PackageReference Include="Microsoft.Extensions.ServiceDiscovery" Version="9.2.0" />
1212
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.11.1" />
1313
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.11.2" />
1414
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.11.2" />

start/Api/Api.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
<ImplicitUsings>enable</ImplicitUsings>
66
</PropertyGroup>
77
<ItemGroup>
8-
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.2" />
8+
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.4" />
99
</ItemGroup>
1010
</Project>

start/MyWeatherHub/MyWeatherHub.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
<ImplicitUsings>enable</ImplicitUsings>
66
</PropertyGroup>
77
<ItemGroup>
8-
<PackageReference Include="Microsoft.AspNetCore.Components.QuickGrid" Version="9.0.2" />
9-
<PackageReference Include="Microsoft.Extensions.ApiDescription.Client" Version="9.0.2">
8+
<PackageReference Include="Microsoft.AspNetCore.Components.QuickGrid" Version="9.0.4" />
9+
<PackageReference Include="Microsoft.Extensions.ApiDescription.Client" Version="9.0.4">
1010
<PrivateAssets>all</PrivateAssets>
1111
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1212
</PackageReference>

workshop/1-setup.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ For the best experience, we recommend using Visual Studio 2022 with the .NET Asp
2424
2525
## Install Latest .NET Aspire Templates
2626

27-
Run the following command to intall .NET Aspire 9.1 templates.
27+
Run the following command to intall .NET Aspire 9.2 templates.
2828

2929
```cli
30-
dotnet new install Aspire.ProjectTemplates::9.1.0 --force
30+
dotnet new install Aspire.ProjectTemplates::9.2.0 --force
3131
```
3232

3333
## Test Installation

workshop/10-container-management.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ Ready to make your Redis container stick around? Let's update our App Host:
3838

3939
```csharp
4040
var cache = builder.AddRedis("cache")
41-
.WithRedisCommander();
41+
.WithRedisInsight();
4242
```
4343

4444
3. Add the magical `.WithLifetime` method:
4545

4646
```csharp
4747
var cache = builder.AddRedis("cache")
48-
.WithRedisCommander()
48+
.WithRedisInsight()
4949
.WithLifetime(ContainerLifetime.Persistent);
5050
```
5151

@@ -81,7 +81,7 @@ Named volumes are the simplest way to persist data. They're managed by Docker bu
8181

8282
```csharp
8383
var cache = builder.AddRedis("cache")
84-
.WithRedisCommander()
84+
.WithRedisInsight()
8585
.WithLifetime(ContainerLifetime.Persistent)
8686
.WithDataVolume("my-redis-data");
8787
```
@@ -94,7 +94,7 @@ Sometimes you want to see and modify your container's files directly. That's whe
9494

9595
```csharp
9696
var cache = builder.AddRedis("cache")
97-
.WithRedisCommander()
97+
.WithRedisInsight()
9898
.WithLifetime(ContainerLifetime.Persistent)
9999
.WithDataBindMount(@"C:\Redis\Data");
100100
```
@@ -107,7 +107,7 @@ Redis has its own data persistence mechanisms. We can configure Redis to save sn
107107

108108
```csharp
109109
var cache = builder.AddRedis("cache")
110-
.WithRedisCommander()
110+
.WithRedisInsight()
111111
.WithLifetime(ContainerLifetime.Persistent)
112112
.WithDataVolume("my-redis-data")
113113
.WithPersistence(interval: TimeSpan.FromMinutes(5), keysChangedThreshold: 100);
@@ -137,10 +137,10 @@ This is an amazing way to test resilience without restarting your entire debug s
137137
Time to see all this in action:
138138

139139
1. Start the App Host project
140-
2. When the dashboard opens, open Redis Commander and create a test key
140+
2. When the dashboard opens, open Redis Insight and create a test key
141141
3. Stop the App Host completely
142142
4. Start the App Host again - notice how much faster Redis starts up?
143-
5. Check Redis Commander - your test key should still be there!
143+
5. Check Redis Insight - your test key should still be there!
144144
6. Try stopping just the Redis container using the dashboard controls
145145
7. Watch how your application handles the Redis outage
146146
8. Start Redis again and see your application recover

workshop/3-dashboard-apphost.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,12 @@ Before continuing, consider some common terminology used in .NET Aspire:
9999

100100
1. Click on the `Trace` or the `Details` to see the error message and stack trace.
101101

102+
## The Dashboard Resource Graph
103+
104+
We saw the table of resources in the .NET Aspire dashboard and that's a nice list of our resources, and we'll see that grow as our application system starts to utilize more resources. Additionally, there is a **Graph** view of resources available by clicking the **Graph** text just above the table.
105+
106+
![.NET Aspire Dashboard Resource Graph](./media/dashboard-graph.png)
107+
108+
This graph is generated based on the references and relationships you configure for your application.
109+
102110
**Next**: [Module #4: Service Discovery](./4-servicediscovery.md)

workshop/5-integrations.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ With the NuGet package installed, we can add Redis to our App Host:
2929
.WithReference(cache);
3030
```
3131

32-
1. Additionally, we could configure [Redis Commander](https://joeferner.github.io/redis-commander/), a Redis management tool. As part of the `Aspire.Hosting.Redis` package, Redis Commander is available in the same integration. To add Redis Commander, update the code adding the Redis resource to call the `WithRedisCommander()` method on the returned builder:
32+
1. Additionally, we could configure [Redis Insight](https://github.com/RedisInsight/RedisInsight), a Redis management tool from the Redis team. As part of the `Aspire.Hosting.Redis` package, Redis Insight is available in the same integration. To add Redis Insight, update the code adding the Redis resource to call the `WithRedisInsight()` method on the returned builder:
3333
3434
```csharp
3535
var cache = builder.AddRedis("cache")
36-
.WithRedisCommander();
36+
.WithRedisInsight();
3737
```
3838

3939
## Run the application
@@ -88,11 +88,11 @@ We will add the _Output caching_ Redis client integration to our `Api` project.
8888

8989
![Output caching in action](./media/output-caching.png)
9090

91-
1. You can also see the cached response in Redis Commander. Open Redis Commander by clicking on the `cache-commander` endpoint in the dashboard. Under stats you will see connections and commands processed.
91+
1. You can also see the cached response in Redis Insight. Open Redis Insight by clicking on the `cache-insight` endpoint in the dashboard. Under stats you will see connections and commands processed.
9292

93-
![Redis Commander](./media/redis-commander.png)
93+
![Redis Insight](./media/redis-insight.png)
9494

95-
1. In addition, you can see logs for the Redis cache and Redis Commander in the `Console` tab.
95+
1. In addition, you can see logs for the Redis cache and Redis Insight in the `Console` tab.
9696

9797
![Redis logs](./media/redis-logs.png)
9898

@@ -119,7 +119,7 @@ var cache = builder.AddRedis("cache")
119119

120120
## Summary
121121

122-
In this section, we added a Redis hosting integration to the App Host and Redis output caching client integration in the API. We saw how the response was cached in the Redis cache and how the second and subsequent requests were much faster than the first one. We also saw how to use Redis Commander to manage the Redis cache.
122+
In this section, we added a Redis hosting integration to the App Host and Redis output caching client integration in the API. We saw how the response was cached in the Redis cache and how the second and subsequent requests were much faster than the first one. We also saw how to use Redis Insight to manage the Redis cache.
123123

124124
There are many more Aspire integrations available that you can use to integrate with your services. You can find the list of available integrations [in the .NET Aspire documentation](https://learn.microsoft.com/dotnet/aspire/fundamentals/integrations-overview?tabs=dotnet-cli#available-integrations).
125125

workshop/media/dashboard-graph.png

49.5 KB
Loading

workshop/media/dashboard.png

18.1 KB
Loading

workshop/media/redis-insight.png

53.6 KB
Loading

workshop/media/redis-logs.png

-37.4 KB
Loading

workshop/media/redis-started.png

-10.9 KB
Loading

0 commit comments

Comments
 (0)