Skip to content

Commit 2577bca

Browse files
authored
caching tutorial fixes (#875)
1 parent 2b028e1 commit 2577bca

File tree

1 file changed

+23
-16
lines changed

1 file changed

+23
-16
lines changed

docs/caching/caching-components.md

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -43,22 +43,29 @@ Visual Studio creates a new .NET Aspire solution that consists of the following
4343

4444
## Configure the App Host project
4545

46-
Update the _Program.cs_ file of the `AspireRedis.AppHost` project to match the following code:
46+
1. Add the [.NET Aspire Hosting Redis](https://www.nuget.org/packages/Aspire.Hosting.Redis) package to the `AspireRedis.AppHost` project:
4747

48-
```csharp
49-
var builder = DistributedApplication.CreateBuilder(args);
50-
51-
var redis = builder.AddRedis("cache");
52-
53-
var apiservice = builder.AddProject<Projects.AspireRedis_ApiService>("apiservice")
54-
.WithReference(redis);
48+
```dotnetcli
49+
dotnet add package Aspire.Hosting.Redis --prerelease
50+
```
5551
56-
builder.AddProject<Projects.AspireRedis_Web>("webfrontend")
57-
.WithReference(apiservice)
58-
.WithReference(redis);
52+
2. Update the _Program.cs_ file of the `AspireRedis.AppHost` project to match the following code:
5953
60-
builder.Build().Run();
61-
```
54+
```csharp
55+
var builder = DistributedApplication.CreateBuilder(args);
56+
57+
var redis = builder.AddRedis("cache");
58+
59+
var apiservice = builder.AddProject<Projects.AspireRedis_ApiService>("apiservice")
60+
.WithReference(redis);
61+
62+
builder.AddProject<Projects.AspireRedis_Web>("webfrontend")
63+
.WithExternalHttpEndpoints()
64+
.WithReference(apiservice)
65+
.WithReference(redis);
66+
67+
builder.Build().Run();
68+
```
6269
6370
The preceding code creates a local Redis container instance and configures the UI and API to use the instance automatically for both output and distributed caching. The code also configures communication between the frontend UI and the backend API using service discovery. With .NET Aspire's implicit service discovery, setting up and managing service connections is streamlined for developer productivity. In the context of this tutorial, the feature simplifies how you connect to Redis.
6471
@@ -78,9 +85,9 @@ Configuring connection string with this method, while functional, requires dupli
7885

7986
1. Add the [.NET Aspire StackExchange Redis output caching](stackexchange-redis-output-caching-component.md) component packages to your `AspireRedis.Web` app:
8087

81-
```dotnetcli
82-
dotnet add package Aspire.StackExchange.Redis.OutputCaching --prerelease
83-
```
88+
```dotnetcli
89+
dotnet add package Aspire.StackExchange.Redis.OutputCaching --prerelease
90+
```
8491
8592
1. In the _Program.cs_ file of the `AspireRedis.Web` Blazor project, immediately after the line `var builder = WebApplication.CreateBuilder(args);`, add a call to the <xref:Microsoft.Extensions.Hosting.AspireRedisOutputCacheExtensions.AddRedisOutputCache%2A> extension method:
8693

0 commit comments

Comments
 (0)