# IPortAllocator Methods

- Package: [Aspire.Hosting](/reference/api/csharp/aspire.hosting.md)
- Type: [IPortAllocator](/reference/api/csharp/aspire.hosting/iportallocator.md)
- Kind: `Methods`
- Members: `2`

Provides port allocation functionality for resources.

## AddUsedPort(int)

- Name: `AddUsedPort(int)`
- Modifiers: `abstract`

Marks a port as used to prevent it from being allocated.

```csharp
public interface IPortAllocator
{
    public abstract void AddUsedPort(
        int port)
    {
        // ...
    }
}
```

## Parameters

- `port` (`int`)
  The port number to mark as used.

## AllocatePort

- Name: `AllocatePort`
- Modifiers: `abstract`
- Returns: `int`

Allocates a port that is not currently in use.

```csharp
public interface IPortAllocator
{
    public abstract int AllocatePort()
    {
        // ...
    }
}
```

## Returns

`int` -- An available port number.
