# DistributedApplicationFactory Methods

- Package: [Aspire.Hosting.Testing](/reference/api/csharp/aspire.hosting.testing.md)
- Type: [DistributedApplicationFactory](/reference/api/csharp/aspire.hosting.testing/distributedapplicationfactory.md)
- Kind: `Methods`
- Members: `6`

Factory for creating a distributed application for testing.

## CreateHttpClient(string, string?)

- Name: `CreateHttpClient(string, string?)`
- Returns: `HttpClient`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/5bd693ae1897dee5e2ce71c2cc08879c1c7eff51/src/Aspire.Hosting.Testing/DistributedApplicationFactory.cs#L82-L85)

Creates an instance of `Http.HttpClient` that is configured to route requests to the specified resource and endpoint.

```csharp
public class DistributedApplicationFactory
{
    public HttpClient CreateHttpClient(
        string resourceName,
        string? endpointName = null)
    {
        // ...
    }
}
```

## Parameters

- `resourceName` (`string`)
- `endpointName` (`string?`) `optional`

## Returns

`HttpClient` -- The `Http.HttpClient`.

## Dispose

- Name: `Dispose`
- Modifiers: `virtual`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/5bd693ae1897dee5e2ce71c2cc08879c1c7eff51/src/Aspire.Hosting.Testing/DistributedApplicationFactory.cs#L473)

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

```csharp
public class DistributedApplicationFactory
{
    public virtual void Dispose()
    {
        // ...
    }
}
```

## DisposeAsync

- Name: `DisposeAsync`
- Modifiers: `virtual`
- Returns: `ValueTask`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/5bd693ae1897dee5e2ce71c2cc08879c1c7eff51/src/Aspire.Hosting.Testing/DistributedApplicationFactory.cs#L478-L528)

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously.

```csharp
public class DistributedApplicationFactory
{
    public virtual ValueTask DisposeAsync()
    {
        // ...
    }
}
```

## Returns

`ValueTask` -- A task that represents the asynchronous dispose operation.

## GetConnectionString(string)

- Name: `GetConnectionString(string)`
- Returns: `ValueTask<string?>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/5bd693ae1897dee5e2ce71c2cc08879c1c7eff51/src/Aspire.Hosting.Testing/DistributedApplicationFactory.cs#L96-L99)

Gets the connection string for the specified resource.

```csharp
public class DistributedApplicationFactory
{
    public ValueTask<string?> GetConnectionString(
        string resourceName)
    {
        // ...
    }
}
```

## Parameters

- `resourceName` (`string`)
  The resource name.

## Returns

`ValueTask<string?>` -- The connection string for the specified resource.

## Exceptions

- `ArgumentException` -- The resource was not found or does not expose a connection string.

## GetEndpoint(string, string?)

- Name: `GetEndpoint(string, string?)`
- Returns: `Uri`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/5bd693ae1897dee5e2ce71c2cc08879c1c7eff51/src/Aspire.Hosting.Testing/DistributedApplicationFactory.cs#L112-L115)

Gets the endpoint for the specified resource.

```csharp
public class DistributedApplicationFactory
{
    public Uri GetEndpoint(
        string resourceName,
        string? endpointName = null)
    {
        // ...
    }
}
```

## Parameters

- `resourceName` (`string`)
  The resource name.
- `endpointName` (`string?`) `optional`
  The optional endpoint name. If none are specified, the single defined endpoint is returned.

## Returns

`Uri` -- A URI representation of the endpoint.

## Exceptions

- `ArgumentException` -- The resource was not found, no matching endpoint was found, or multiple endpoints were found.
- `InvalidOperationException` -- The resource has no endpoints.

## StartAsync(CancellationToken)

- Name: `StartAsync(CancellationToken)`
- Returns: `Task`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/5bd693ae1897dee5e2ce71c2cc08879c1c7eff51/src/Aspire.Hosting.Testing/DistributedApplicationFactory.cs#L70-L74)

Starts the application.

```csharp
public class DistributedApplicationFactory
{
    public Task StartAsync(
        CancellationToken cancellationToken = default(CancellationToken))
    {
        // ...
    }
}
```

## Parameters

- `cancellationToken` (`CancellationToken`) `optional`
  A token used to signal cancellation.

## Returns

`Task` -- A `Tasks.Task` representing the completion of the operation.
