# ExternalServiceBuilderExtensions Methods

- Package: [Aspire.Hosting](/reference/api/csharp/aspire.hosting.md)
- Type: [ExternalServiceBuilderExtensions](/reference/api/csharp/aspire.hosting/externalservicebuilderextensions.md)
- Kind: `Methods`
- Members: `4`

Provides extension methods for adding external services to an application.

## AddExternalService(IDistributedApplicationBuilder, string, string)

- Name: `AddExternalService(IDistributedApplicationBuilder, string, string)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<ExternalServiceResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ExternalServiceBuilderExtensions.cs#L30-L39)

Adds an external service resource to the distributed application with the specified URL.

```csharp
public static class ExternalServiceBuilderExtensions
{
    public static IResourceBuilder<ExternalServiceResource> AddExternalService(
        this IDistributedApplicationBuilder builder,
        string name,
        string url)
    {
        // ...
    }
}
```

## Parameters

- `builder` ([IDistributedApplicationBuilder](/reference/api/csharp/aspire.hosting/idistributedapplicationbuilder.md))
  The distributed application builder.
- `name` (`string`)
  The name of the resource.
- `url` (`string`)
  The URL of the external service.

## Returns

`IResourceBuilder<ExternalServiceResource>` -- An `ApplicationModel.IResourceBuilder`1` instance.

## ATS metadata

### Ignored by ATS

- Reason: Polyglot app hosts use the internal addExternalService dispatcher export.

## AddExternalService(IDistributedApplicationBuilder, string, Uri)

- Name: `AddExternalService(IDistributedApplicationBuilder, string, Uri)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<ExternalServiceResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ExternalServiceBuilderExtensions.cs#L71-L75)

Adds an external service resource to the distributed application with the specified URI.

```csharp
public static class ExternalServiceBuilderExtensions
{
    public static IResourceBuilder<ExternalServiceResource> AddExternalService(
        this IDistributedApplicationBuilder builder,
        string name,
        Uri uri)
    {
        // ...
    }
}
```

## Parameters

- `builder` ([IDistributedApplicationBuilder](/reference/api/csharp/aspire.hosting/idistributedapplicationbuilder.md))
  The distributed application builder.
- `name` (`string`)
  The name of the resource.
- `uri` (`Uri`)
  The URI of the external service.

## Returns

`IResourceBuilder<ExternalServiceResource>` -- An `ApplicationModel.IResourceBuilder`1` instance.

## ATS metadata

### Ignored by ATS

- Reason: Polyglot app hosts use the internal addExternalService dispatcher export.

## AddExternalService(IDistributedApplicationBuilder, string, IResourceBuilder<ParameterResource>)

- Name: `AddExternalService(IDistributedApplicationBuilder, string, IResourceBuilder<ParameterResource>)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<ExternalServiceResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ExternalServiceBuilderExtensions.cs#L88-L92)

Adds an external service resource to the distributed application with the URL coming from the specified parameter.

```csharp
public static class ExternalServiceBuilderExtensions
{
    public static IResourceBuilder<ExternalServiceResource> AddExternalService(
        this IDistributedApplicationBuilder builder,
        string name,
        IResourceBuilder<ParameterResource> urlParameter)
    {
        // ...
    }
}
```

## Parameters

- `builder` ([IDistributedApplicationBuilder](/reference/api/csharp/aspire.hosting/idistributedapplicationbuilder.md))
  The distributed application builder.
- `name` (`string`)
  The name of the resource.
- `urlParameter` (`IResourceBuilder<ParameterResource>`)
  The parameter containing the URL of the external service.

## Returns

`IResourceBuilder<ExternalServiceResource>` -- An `ApplicationModel.IResourceBuilder`1` instance.

## ATS metadata

### Ignored by ATS

- Reason: Polyglot app hosts use the internal addExternalService dispatcher export.

## WithHttpHealthCheck(IResourceBuilder<ExternalServiceResource>, string?, int?)

- Name: `WithHttpHealthCheck(IResourceBuilder<ExternalServiceResource>, string?, int?)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<ExternalServiceResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ExternalServiceBuilderExtensions.cs#L210-L269)

Adds a health check to the external service resource.

```csharp
public static class ExternalServiceBuilderExtensions
{
    public static IResourceBuilder<ExternalServiceResource> WithHttpHealthCheck(
        this IResourceBuilder<ExternalServiceResource> builder,
        string? path = null,
        int? statusCode = null)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<ExternalServiceResource>`)
  The external service resource builder.
- `path` (`string?`) `optional`
  The relative path to use for the HTTP health check.
- `statusCode` (`int?`) `optional`
  The expected HTTP status code for a healthy response. Defaults to `200`.

## Returns

`IResourceBuilder<ExternalServiceResource>` -- The `ApplicationModel.IResourceBuilder`1` for chaining.

## Remarks

This method adds a health check to the health check service which polls the specified external service on a periodic basis. The address is based on the URL of the external service. A path for the health check request can be specified. The expected status code is set to `200` by default but a different one can be specified.

## ATS metadata

### Ignored by ATS

- Reason: Polyglot app hosts use the internal withHttpHealthCheck export wrapper.
