# EndpointReference

- Kind: `class`
- Package: [Aspire.Hosting](/reference/api/csharp/aspire.hosting.md)
- Version: `13.3.0`
- Namespace: `Aspire.Hosting.ApplicationModel`
- Target framework: `net8.0`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ApplicationModel/EndpointReference.cs)
- Implements: [IExpressionValue](/reference/api/csharp/aspire.hosting/iexpressionvalue.md), [IManifestExpressionProvider](/reference/api/csharp/aspire.hosting/imanifestexpressionprovider.md), [IValueProvider](/reference/api/csharp/aspire.hosting/ivalueprovider.md), [IValueWithReferences](/reference/api/csharp/aspire.hosting/ivaluewithreferences.md)

Represents an endpoint reference for a resource with endpoints.

## Definition

```csharp
namespace Aspire.Hosting.ApplicationModel;

public sealed class EndpointReference
    : Aspire.Hosting.ApplicationModel.IExpressionValue,
      Aspire.Hosting.ApplicationModel.IManifestExpressionProvider,
      Aspire.Hosting.ApplicationModel.IValueProvider,
      Aspire.Hosting.ApplicationModel.IValueWithReferences
{
    // ...
}
```

## ATS metadata

### ATS export

- Type ID: `Aspire.Hosting/EndpointReference`
- Public instance properties are exported as ATS capabilities.
- Public instance methods are exported as ATS capabilities.

## Constructors

- [EndpointReference(IResourceWithEndpoints, EndpointAnnotation, NetworkIdentifier?)](/reference/api/csharp/aspire.hosting/endpointreference/constructors.md#constructor-iresourcewithendpoints-endpointannotation-networkidentifier) -- Creates a new instance of [EndpointReference](/reference/api/csharp/aspire.hosting/endpointreference.md) with the specified endpoint name.
- [EndpointReference(IResourceWithEndpoints, EndpointAnnotation)](/reference/api/csharp/aspire.hosting/endpointreference/constructors.md#constructor-iresourcewithendpoints-endpointannotation) -- Creates a new instance of [EndpointReference](/reference/api/csharp/aspire.hosting/endpointreference.md) with the specified endpoint name.
- [EndpointReference(IResourceWithEndpoints, string, NetworkIdentifier?)](/reference/api/csharp/aspire.hosting/endpointreference/constructors.md#constructor-iresourcewithendpoints-string-networkidentifier) -- Creates a new instance of [EndpointReference](/reference/api/csharp/aspire.hosting/endpointreference.md) with the specified endpoint name.
- [EndpointReference(IResourceWithEndpoints, string)](/reference/api/csharp/aspire.hosting/endpointreference/constructors.md#constructor-iresourcewithendpoints-string) -- Creates a new instance of [EndpointReference](/reference/api/csharp/aspire.hosting/endpointreference.md) with the specified endpoint name.

## Properties

- [ContextNetworkID](/reference/api/csharp/aspire.hosting/endpointreference/properties.md#contextnetworkid) : [NetworkIdentifier?](/reference/api/csharp/aspire.hosting/networkidentifier.md) `get` -- The ID of the network that serves as the context for the EndpointReference. The reference will be resolved in the context of this network, which may be different from the network associated with the default network of the referenced Endpoint.
- [EndpointAnnotation](/reference/api/csharp/aspire.hosting/endpointreference/properties.md#endpointannotation) : [EndpointAnnotation](/reference/api/csharp/aspire.hosting/endpointannotation.md) `get` -- Gets the endpoint annotation associated with the endpoint reference.
- [EndpointName](/reference/api/csharp/aspire.hosting/endpointreference/properties.md#endpointname) : `string` `get` -- Gets the name of the endpoint associated with the endpoint reference.
- [ErrorMessage](/reference/api/csharp/aspire.hosting/endpointreference/properties.md#errormessage) : `string?` `get; init` -- Gets or sets a custom error message to be thrown when the endpoint annotation is not found.
- [ExcludeReferenceEndpoint](/reference/api/csharp/aspire.hosting/endpointreference/properties.md#excludereferenceendpoint) : `bool` `get` -- Gets a value indicating whether this endpoint is excluded from the default set when referencing the resource's endpoints.
- [Exists](/reference/api/csharp/aspire.hosting/endpointreference/properties.md#exists) : `bool` `get` -- Gets a value indicating whether the endpoint exists.
- [Host](/reference/api/csharp/aspire.hosting/endpointreference/properties.md#host) : `string` `get` -- Gets the host for this endpoint.
- [IsAllocated](/reference/api/csharp/aspire.hosting/endpointreference/properties.md#isallocated) : `bool` `get` -- Gets a value indicating whether the endpoint is allocated.
- [IsHttp](/reference/api/csharp/aspire.hosting/endpointreference/properties.md#ishttp) : `bool` `get` -- Gets a value indicating whether the endpoint uses HTTP scheme.
- [IsHttps](/reference/api/csharp/aspire.hosting/endpointreference/properties.md#ishttps) : `bool` `get` -- Gets a value indicating whether the endpoint uses HTTPS scheme.
- [IsHttpSchemeNamedEndpoint](/reference/api/csharp/aspire.hosting/endpointreference/properties.md#ishttpschemenamedendpoint) : `bool` `get` -- Gets a value indicating whether the endpoint name is "http" or "https", ignoring case. This is a convention used to identify endpoints that will be resolved based on the scheme of the endpoint in service discovery rather than by the specific endpoint name. This is done to allow http endpoints that are dynamically updated to https to be mapped correctly despite the endpoint name no longer matching the scheme.
- [Port](/reference/api/csharp/aspire.hosting/endpointreference/properties.md#port) : `int` `get` -- Gets the port for this endpoint.
- [Resource](/reference/api/csharp/aspire.hosting/endpointreference/properties.md#resource) : [IResourceWithEndpoints](/reference/api/csharp/aspire.hosting/iresourcewithendpoints.md) `get` -- Gets the resource owner of the endpoint reference.
- [Scheme](/reference/api/csharp/aspire.hosting/endpointreference/properties.md#scheme) : `string` `get` -- Gets the scheme for this endpoint.
- [TargetPort](/reference/api/csharp/aspire.hosting/endpointreference/properties.md#targetport) : `int?` `get` -- Gets the target port for this endpoint. If the port is dynamically allocated, this will return `null`.
- [TlsEnabled](/reference/api/csharp/aspire.hosting/endpointreference/properties.md#tlsenabled) : `bool` `get` -- Gets a value indicating whether TLS is enabled for this endpoint.
- [Url](/reference/api/csharp/aspire.hosting/endpointreference/properties.md#url) : `string` `get` -- Gets the URL for this endpoint.

## Methods

- [GetTlsValue(ReferenceExpression, ReferenceExpression)](/reference/api/csharp/aspire.hosting/endpointreference/methods.md#gettlsvalue-referenceexpression-referenceexpression) : [ReferenceExpression](/reference/api/csharp/aspire.hosting/referenceexpression.md) `ats export` -- Creates a conditional [ReferenceExpression](/reference/api/csharp/aspire.hosting/referenceexpression.md) that resolves to `enabledValue` when [EndpointAnnotation.TlsEnabled](/reference/api/csharp/aspire.hosting/endpointannotation/properties.md#tlsenabled) is `true` on this endpoint, or to `disabledValue` otherwise.
- [GetValueAsync(CancellationToken)](/reference/api/csharp/aspire.hosting/endpointreference/methods.md#getvalueasync-cancellationtoken) : `ValueTask<string?>` `ats export` -- Gets the URL of the endpoint asynchronously. Waits for the endpoint to be allocated if necessary.
- [GetValueAsync(ValueProviderContext, CancellationToken)](/reference/api/csharp/aspire.hosting/endpointreference/methods.md#getvalueasync-valueprovidercontext-cancellationtoken) : `ValueTask<string?>` `ats ignored` -- Gets the URL of the endpoint asynchronously. Waits for the endpoint to be allocated if necessary.
- [Property(EndpointProperty)](/reference/api/csharp/aspire.hosting/endpointreference/methods.md#property-endpointproperty) : [EndpointReferenceExpression](/reference/api/csharp/aspire.hosting/endpointreferenceexpression.md) `ats export` -- Gets the specified property expression of the endpoint.
