# TerminalService

- Kind: `class`
- Package: [Aspire.Hosting](/reference/api/csharp/aspire.hosting.md)
- Version: `13.6.0`
- Namespace: `Aspire.Hosting.ApplicationModel`
- Target framework: `net10.0`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/f4c27f2d43ddc1cacd0dd083b30d1fea1cee7a62/src/Aspire.Hosting/ApplicationModel/TerminalService.cs)
- Implements: `IAsyncDisposable`

Manages terminals created and owned by the AppHost.

## Definition

```csharp
namespace Aspire.Hosting.ApplicationModel;

public sealed class TerminalService
    : System.IAsyncDisposable
{
    // ...
}
```

## Remarks

Two experiences share this service: terminals displayed by [IInteractionService.PromptTerminalAsync(string, AspireTerminal, TerminalInteractionOptions?, CancellationToken)](/reference/api/csharp/aspire.hosting/iinteractionservice/methods.md#promptterminalasync-string-aspireterminal-terminalinteractionoptions-cancellationtoken) and terminals shown as tabs in the dashboard's terminal dock. They differ only in [TerminalPlacement](/reference/api/csharp/aspire.hosting/terminalplacement.md); the lifetime, transport, and automation machinery is identical.

This is distinct from the terminal host, which exists solely to surface terminals for DCP-owned processes. Those are owned by the resource, reachable over a Unix domain socket, and are not tracked here.

Resolve it from the built AppHost's service provider: `app.Services.GetRequiredService<TerminalService>()`. Only creation and lookup are public; the members the dashboard uses to attach transports and watch the dock's tab list are internal, because they are transport plumbing rather than something an AppHost author calls.

Each dashboard metadata watcher buffers up to 64 updates by default. Set `ASPIRE_TERMINAL_WATCH_BUFFER_CAPACITY` to a positive integer in the AppHost's configuration before starting the application to tune this limit. Overflow replaces queued changes with a current snapshot while preserving the latest pending request to show the dock.

## Methods

- [CreateTerminal(TerminalLaunchOptions)](/reference/api/csharp/aspire.hosting/terminalservice/methods.md#createterminal-terminallaunchoptions) : [AspireTerminal](/reference/api/csharp/aspire.hosting/aspireterminal.md) -- Creates a terminal. The workload does not start until something needs it: the first viewer attaching, or the first automation call.
- [DisposeAsync](/reference/api/csharp/aspire.hosting/terminalservice/methods.md#disposeasync) : `ValueTask` -- Stops and awaits teardown of every terminal this service owns.
- [TryGetTerminal(string, AspireTerminal?)](/reference/api/csharp/aspire.hosting/terminalservice/methods.md#trygetterminal-string-aspireterminal) : `bool` -- Gets a terminal by id.
