# EndpointReference Constructors

- Package: [Aspire.Hosting](/reference/api/csharp/aspire.hosting.md)
- Type: [EndpointReference](/reference/api/csharp/aspire.hosting/endpointreference.md)
- Kind: `Constructors`
- Members: `4`

Represents an endpoint reference for a resource with endpoints.

## EndpointReference(IResourceWithEndpoints, EndpointAnnotation, NetworkIdentifier?)

- Name: `Constructor(IResourceWithEndpoints, EndpointAnnotation, NetworkIdentifier?)`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ApplicationModel/EndpointReference.cs#L253-L262)

Creates a new instance of [EndpointReference](/reference/api/csharp/aspire.hosting/endpointreference.md) with the specified endpoint name.

```csharp
public sealed class EndpointReference
{
    public EndpointReference(
        IResourceWithEndpoints owner,
        EndpointAnnotation endpoint,
        NetworkIdentifier? contextNetworkID)
    {
        // ...
    }
}
```

## Parameters

- `owner` ([IResourceWithEndpoints](/reference/api/csharp/aspire.hosting/iresourcewithendpoints.md))
  The resource with endpoints that owns the referenced endpoint.
- `endpoint` ([EndpointAnnotation](/reference/api/csharp/aspire.hosting/endpointannotation.md))
  The endpoint annotation.
- `contextNetworkID` ([NetworkIdentifier?](/reference/api/csharp/aspire.hosting/networkidentifier.md))
  The ID of the network that serves as the context for the EndpointReference.

## Remarks

Most Aspire resources are accessed in the context of the "localhost" network (host processes calling other host processes, or host processes calling container via mapped ports). If a [NetworkIdentifier](/reference/api/csharp/aspire.hosting/networkidentifier.md) is specified, the [EndpointReference](/reference/api/csharp/aspire.hosting/endpointreference.md) will always resolve in the context of that network. If the [NetworkIdentifier](/reference/api/csharp/aspire.hosting/networkidentifier.md) is null, the reference will attempt to resolve itself based on the context of the requesting resource.

## EndpointReference(IResourceWithEndpoints, EndpointAnnotation)

- Name: `Constructor(IResourceWithEndpoints, EndpointAnnotation)`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ApplicationModel/EndpointReference.cs#L269-L271)

Creates a new instance of [EndpointReference](/reference/api/csharp/aspire.hosting/endpointreference.md) with the specified endpoint name.

```csharp
public sealed class EndpointReference
{
    public EndpointReference(
        IResourceWithEndpoints owner,
        EndpointAnnotation endpoint)
    {
        // ...
    }
}
```

## Parameters

- `owner` ([IResourceWithEndpoints](/reference/api/csharp/aspire.hosting/iresourcewithendpoints.md))
  The resource with endpoints that owns the referenced endpoint.
- `endpoint` ([EndpointAnnotation](/reference/api/csharp/aspire.hosting/endpointannotation.md))
  The endpoint annotation.

## EndpointReference(IResourceWithEndpoints, string, NetworkIdentifier?)

- Name: `Constructor(IResourceWithEndpoints, string, NetworkIdentifier?)`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ApplicationModel/EndpointReference.cs#L285-L293)

Creates a new instance of [EndpointReference](/reference/api/csharp/aspire.hosting/endpointreference.md) with the specified endpoint name.

```csharp
public sealed class EndpointReference
{
    public EndpointReference(
        IResourceWithEndpoints owner,
        string endpointName,
        NetworkIdentifier? contextNetworkID = null)
    {
        // ...
    }
}
```

## Parameters

- `owner` ([IResourceWithEndpoints](/reference/api/csharp/aspire.hosting/iresourcewithendpoints.md))
  The resource with endpoints that owns the referenced endpoint.
- `endpointName` (`string`)
  The name of the endpoint.
- `contextNetworkID` ([NetworkIdentifier?](/reference/api/csharp/aspire.hosting/networkidentifier.md)) `optional`
  The ID of the network that serves as the context for the EndpointReference.

## Remarks

Most Aspire resources are accessed in the context of the "localhost" network (host proceses calling other host processes, or host processes calling container via mapped ports). This is why EndpointReference assumes this context unless specified otherwise. However, for container-to-container, or container-to-host communication, you must specify a container network context for the EndpointReference to be resolved correctly.

## EndpointReference(IResourceWithEndpoints, string)

- Name: `Constructor(IResourceWithEndpoints, string)`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ApplicationModel/EndpointReference.cs#L300-L302)

Creates a new instance of [EndpointReference](/reference/api/csharp/aspire.hosting/endpointreference.md) with the specified endpoint name.

```csharp
public sealed class EndpointReference
{
    public EndpointReference(
        IResourceWithEndpoints owner,
        string endpointName)
    {
        // ...
    }
}
```

## Parameters

- `owner` ([IResourceWithEndpoints](/reference/api/csharp/aspire.hosting/iresourcewithendpoints.md))
  The resource with endpoints that owns the referenced endpoint.
- `endpointName` (`string`)
  The name of the endpoint.
