Microsoft.Extensions.ServiceDiscovery.Dns 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.Dns.
dotnet add package Microsoft.Extensions.ServiceDiscovery.Dns --version 8.0.0-preview.7.24251.11
NuGet\Install-Package Microsoft.Extensions.ServiceDiscovery.Dns -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.Dns" 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.Dns --version 8.0.0-preview.7.24251.11
#r "nuget: Microsoft.Extensions.ServiceDiscovery.Dns, 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.Dns as a Cake Addin
#addin nuget:?package=Microsoft.Extensions.ServiceDiscovery.Dns&version=8.0.0-preview.7.24251.11&prerelease

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

Microsoft.Extensions.ServiceDiscovery.Dns

This library provides support for resolving service endpoints using DNS (Domain Name System). It provides two service endpoint providers:

  • DNS, which resolves endpoints using DNS A/AAAA record queries. This means that it can resolve names to IP addresses, but cannot resolve port numbers endpoints. As such, port numbers are assumed to be the default for the protocol (for example, 80 for HTTP and 433 for HTTPS). The benefit of using the DNS provider is that for cases where these default ports are appropriate, clients can spread their requests across hosts. For more information, see Load-balancing with endpoint selectors.

  • DNS SRV, which resolves service names using DNS SRV record queries. This allows it to resolve both IP addresses and port numbers. This is useful for environments which support DNS SRV queries, such as Kubernetes (when configured accordingly).

Resolving service endpoints with DNS

The DNS service endpoint provider resolves endpoints using DNS A/AAAA record queries. This means that it can resolve names to IP addresses, but cannot resolve port numbers endpoints. As such, port numbers are assumed to be the default for the protocol (for example, 80 for HTTP and 433 for HTTPS). The benefit of using the DNS service endpoint provider is that for cases where these default ports are appropriate, clients can spread their requests across hosts. For more information, see Load-balancing with endpoint selectors.

To configure the DNS service endpoint provider in your application, add the DNS service endpoint provider to your host builder's service collection using the AddDnsServiceEndpointProvider method. service discovery as follows:

builder.Services.AddServiceDiscoveryCore();
builder.Services.AddDnsServiceEndpointProvider();

Resolving service endpoints in Kubernetes with DNS SRV

When deploying to Kubernetes, the DNS SRV service endpoint provider can be used to resolve endpoints. For example, the following resource definition will result in a DNS SRV record being created for an endpoint named "default" and an endpoint named "dashboard", both on the service named "basket".

apiVersion: v1
kind: Service
metadata:
  name: basket
spec:
  selector:
    name: basket-service
  clusterIP: None
  ports:
  - name: default
    port: 8080
  - name: dashboard
    port: 8888

To configure a service to resolve the "dashboard" endpoint on the "basket" service, add the DNS SRV service endpoint provider to the host builder as follows:

builder.Services.AddServiceDiscoveryCore();
builder.Services.AddDnsSrvServiceEndpointProvider();

The special port name "default" is used to specify the default endpoint, resolved using the URI http://basket.

As in the previous example, add service discovery to an HttpClient for the basket service:

builder.Services.AddHttpClient<BasketServiceClient>(
    static client => client.BaseAddress = new("http://basket"));

Similarly, the "dashboard" endpoint can be targeted as follows:

builder.Services.AddHttpClient<BasketServiceDashboardClient>(
    static client => client.BaseAddress = new("http://_dashboard.basket"));

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

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
8.0.0-preview.7.24251.11 76 5/7/2024
8.0.0-preview.6.24214.1 150 4/23/2024
8.0.0-preview.5.24201.12 1,068 4/9/2024
8.0.0-preview.4.24156.9 487 3/12/2024
8.0.0-preview.3.24105.21 2,190 2/13/2024
8.0.0-preview.2.23619.3 1,342 12/20/2023
8.0.0-preview.1.23557.2 997 11/14/2023