To model the Valkey resource (ValkeyResource
) in the app host, install the Aspire.Hosting.Valkey NuGet package in the app host project.
dotnet add package Aspire.Hosting.Valkey
<PackageReference Include="Aspire.Hosting.Valkey"
Version="*" />
In your app host project, register the .NET Aspire Valkey as a resource using the AddValkey
method and consume the service using the following methods:
var builder = DistributedApplication.CreateBuilder(args);
var cache = builder.AddValkey("cache");
builder.AddProject<Projects.ExampleProject>()
.WithReference(cache)
The xref:Aspire.Hosting.ResourceBuilderExtensions.WithReference%2A method configures a connection in the ExampleProject
project named cache
. In the :::no-loc text="Program.cs"::: file of ExampleProject
, the Valkey connection can be consumed using:
builder.AddValkey("cache");