TemporaryNetwork Class

A temporary network created from a NetworkDefinition. Dispose the instance to remove the network.

public sealed class TemporaryNetwork : IAsyncDisposable

Remarks

Disposing only removes the network when this instance created it and NetworkDefinition.ReuseId is not set. A network that already existed when TemporaryNetwork.EnsureCreatedAsync ran is adopted and left behind, so pointing a definition at an existing network never destroys it.

Implements

Properties

NameDescription
DefinitionGets the definition owned by this network. It is read-only.
NameGets the network name.
RuntimeGets the container runtime in use.

Gets the definition owned by this network. It is read-only.

public NetworkDefinition Definition { get; }

Property value

NetworkDefinition

Gets the network name.

public string Name { get; }

Property value

string

Gets the container runtime in use.

public ContainerRuntime Runtime { get; }

Property value

ContainerRuntime

Methods

NameDescription
DeleteAsync(CancellationToken)Removes the network.
DisposeAsync()Removes the network when this instance created it and NetworkDefinition.ReuseId is not set. Cleanup is best-effort, bounded in time, and never throws.
EnsureCreatedAsync(CancellationToken)Creates the network if it does not exist yet. An existing network is adopted instead, and is not removed on dispose.
ExistsAsync(CancellationToken)Determines whether the network exists.

DeleteAsync(CancellationToken)

TemporaryNetwork.cs

Removes the network.

net10.0

public Task DeleteAsync(CancellationToken cancellationToken = default)

net11.0

public Task DeleteAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken
A cancellation token.

Returns

Task A task that completes once the network is removed.

Exceptions

InvalidOperationException
The network could not be removed, for instance because a container still uses it.

DisposeAsync()

TemporaryNetwork.cs

Removes the network when this instance created it and NetworkDefinition.ReuseId is not set. Cleanup is best-effort, bounded in time, and never throws.

net10.0

public ValueTask DisposeAsync()

net11.0

public ValueTask DisposeAsync()

Returns

ValueTask A task that completes once cleanup finishes.

EnsureCreatedAsync(CancellationToken)

TemporaryNetwork.cs

Creates the network if it does not exist yet. An existing network is adopted instead, and is not removed on dispose.

net10.0

public Task EnsureCreatedAsync(CancellationToken cancellationToken = default)

net11.0

public Task EnsureCreatedAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken
A cancellation token.

Returns

Task A task that completes once the network exists.

ExistsAsync(CancellationToken)

TemporaryNetwork.cs

Determines whether the network exists.

net10.0

public Task<bool> ExistsAsync(CancellationToken cancellationToken = default)

net11.0

public Task<bool> ExistsAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken
A cancellation token.

Returns

Task<bool> true if the network exists; otherwise, false.