TemporaryNetwork Class
A temporary network created from a NetworkDefinition. Dispose the instance to remove the network.
public sealed class TemporaryNetwork : IAsyncDisposableRemarks
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
| Name | Description |
|---|---|
| Definition | Gets the definition owned by this network. It is read-only. |
| Name | Gets the network name. |
| Runtime | Gets the container runtime in use. |
Definition
TemporaryNetwork.csGets the definition owned by this network. It is read-only.
public NetworkDefinition Definition { get; }Property value
Runtime
TemporaryNetwork.csMethods
| Name | Description |
|---|---|
| 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.csRemoves the network.
net10.0
public Task DeleteAsync(CancellationToken cancellationToken = default)net11.0
public Task DeleteAsync(CancellationToken cancellationToken = default)Parameters
cancellationTokenCancellationToken- 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.csRemoves 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.csCreates 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
cancellationTokenCancellationToken- A cancellation token.
Returns
Task A task that completes once the network exists.
ExistsAsync(CancellationToken)
TemporaryNetwork.csDetermines whether the network exists.
net10.0
public Task<bool> ExistsAsync(CancellationToken cancellationToken = default)net11.0
public Task<bool> ExistsAsync(CancellationToken cancellationToken = default)Parameters
cancellationTokenCancellationToken- A cancellation token.
Returns
Task<bool> true if the network exists; otherwise, false.