Microsoft.Extensions.ServiceDiscovery.Yarp 8.0.0-preview.7.24251.11

The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org. Prefix Reserved
This is a prerelease version of Microsoft.Extensions.ServiceDiscovery.Yarp.
dotnet add package Microsoft.Extensions.ServiceDiscovery.Yarp --version 8.0.0-preview.7.24251.11
NuGet\Install-Package Microsoft.Extensions.ServiceDiscovery.Yarp -Version 8.0.0-preview.7.24251.11
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Microsoft.Extensions.ServiceDiscovery.Yarp" Version="8.0.0-preview.7.24251.11" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Microsoft.Extensions.ServiceDiscovery.Yarp --version 8.0.0-preview.7.24251.11
#r "nuget: Microsoft.Extensions.ServiceDiscovery.Yarp, 8.0.0-preview.7.24251.11"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Microsoft.Extensions.ServiceDiscovery.Yarp as a Cake Addin
#addin nuget:?package=Microsoft.Extensions.ServiceDiscovery.Yarp&version=8.0.0-preview.7.24251.11&prerelease

// Install Microsoft.Extensions.ServiceDiscovery.Yarp as a Cake Tool
#tool nuget:?package=Microsoft.Extensions.ServiceDiscovery.Yarp&version=8.0.0-preview.7.24251.11&prerelease

Microsoft.Extensions.ServiceDiscovery.Yarp

The Microsoft.Extensions.ServiceDiscovery.Yarp library adds support for resolving endpoints for YARP clusters, by implementing a YARP destination resolver.

Usage

Resolving YARP cluster destinations using Service Discovery

The IReverseProxyBuilder.AddServiceDiscoveryDestinationResolver() extension method configures a YARP destination resolver. To use this method, you must also configure YARP itself as described in the YARP documentation, and you must configure .NET Service Discovery via the Microsoft.Extensions.ServiceDiscovery library.

Direct HTTP forwarding using Service Discovery Forwarding HTTP requests using IHttpForwarder

YARP supports direct forwarding of specific requests using the IHttpForwarder interface. This, too, can benefit from service discovery using the Microsoft.Extensions.ServiceDiscovery library. To take advantage of service discovery when using YARP Direct Forwarding, use the IServiceCollection.AddHttpForwarderWithServiceDiscovery method.

For example, consider the following .NET Aspire application:

var builder = WebApplication.CreateBuilder(args);

// Configure service discovery
builder.Services.AddServiceDiscovery();

// Add YARP Direct Forwarding with Service Discovery support
builder.Services.AddHttpForwarderWithServiceDiscovery();

// ... other configuration ...

var app = builder.Build();

// ... other configuration ...

// Map a Direct Forwarder which forwards requests to the resolved "catalogservice" endpoints
app.MapForwarder("/catalog/images/{id}", "http://catalogservice", "/api/v1/catalog/items/{id}/image");

app.Run();

In the above example, the YARP Direct Forwarder will resolve the catalogservice using service discovery, forwarding request sent to the /catalog/images/{id} endpoint to the destination path on the resolved endpoints.

Feedback & contributing

https://github.com/dotnet/aspire

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories (2)

Showing the top 2 popular GitHub repositories that depend on Microsoft.Extensions.ServiceDiscovery.Yarp:

Repository Stars
dotnet/eShop
A reference .NET application implementing an eCommerce site
dotnet/aspire-samples
Version Downloads Last updated
8.0.0-preview.7.24251.11 1,301 5/7/2024
8.0.0-preview.6.24214.1 3,128 4/23/2024
8.0.0-preview.5.24201.12 3,809 4/9/2024
8.0.0-preview.4.24156.9 6,344 3/12/2024
8.0.0-preview.3.24105.21 4,960 2/13/2024
8.0.0-preview.2.23619.3 7,917 12/20/2023
8.0.0-preview.1.23557.2 7,821 11/14/2023