ResourceNotificationService Methods
Dispose Section titled Dispose public class ResourceNotificationService{ public void Dispose() { // ... }}PublishUpdateAsync(IResource, string, Func<CustomResourceSnapshot, CustomResourceSnapshot>) Section titled PublishUpdateAsync(IResource, string, Func<CustomResourceSnapshot, CustomResourceSnapshot>) Task CustomResourceSnapshot for a resource. public class ResourceNotificationService{ public Task PublishUpdateAsync( IResource resource, string resourceId, Func<CustomResourceSnapshot, CustomResourceSnapshot> stateFactory) { // ... }}Parameters
resource IResource The resource to update resourceId string The id of the resource. stateFactory Func<CustomResourceSnapshot, CustomResourceSnapshot> A factory that creates the new state based on the previous state. PublishUpdateAsync(IResource, Func<CustomResourceSnapshot, CustomResourceSnapshot>) Section titled PublishUpdateAsync(IResource, Func<CustomResourceSnapshot, CustomResourceSnapshot>) Task CustomResourceSnapshot for a resource. public class ResourceNotificationService{ public Task PublishUpdateAsync( IResource resource, Func<CustomResourceSnapshot, CustomResourceSnapshot> stateFactory) { // ... }}Parameters
resource IResource The resource to update stateFactory Func<CustomResourceSnapshot, CustomResourceSnapshot> A factory that creates the new state based on the previous state. TryGetCurrentState(string, ResourceEvent?) Section titled TryGetCurrentState(string, ResourceEvent?) bool public class ResourceNotificationService{ public bool TryGetCurrentState( string resourceId, out ResourceEvent? resourceEvent) { // ... }}Parameters
resourceId string The resource id. This id can either exactly match the unique id of the resource or the displayed resource name if the resource name doesn't have duplicates (i.e. replicas). resourceEvent ResourceEvent? When this method returns, contains the ResourceEvent for the specified resource id, if found; otherwise, null. Returns
bool true if specified resource id was found; otherwise, false. Remarks
A resource id can be either the unique id of the resource or the displayed resource name.
Projects, executables and containers typically have a unique id that combines the display name and a unique suffix. For example, a resource named cache could have a resource id of cache-abcdwxyz. This id is used to uniquely identify the resource in the app host.
The resource name can be also be used to retrieve the resource state, but it must be unique. If there are multiple resources with the same name, then this method will not return a match. For example, if a resource named cache has multiple replicas, then specifing cache won't return a match.
WaitForDependenciesAsync(IResource, CancellationToken) Section titled WaitForDependenciesAsync(IResource, CancellationToken) Task public class ResourceNotificationService{ public Task WaitForDependenciesAsync( IResource resource, CancellationToken cancellationToken) { // ... }}Parameters
resource IResource The resource with dependencies to wait for. cancellationToken CancellationToken The cancellation token. Returns
Task A task. Exceptions
WaitForResourceAsync(string, string?, CancellationToken) Section titled WaitForResourceAsync(string, string?, CancellationToken) Task KnownResourceStates for common states. public class ResourceNotificationService{ public Task WaitForResourceAsync( string resourceName, string? targetState = null, CancellationToken cancellationToken = default(CancellationToken)) { // ... }}Parameters
resourceName string The name of the resource. targetState string? optional The state to wait for the resource to transition to. See KnownResourceStates for common states. cancellationToken CancellationToken optional A Threading.CancellationToken. Returns
Task A Tasks.Task representing the wait operation. Remarks
cancellationToken is signaled, this method will throw OperationCanceledException. WaitForResourceAsync(string, IEnumerable<string>, CancellationToken) Section titled WaitForResourceAsync(string, IEnumerable<string>, CancellationToken) Task<string> KnownResourceStates for common states. public class ResourceNotificationService{ public Task<string> WaitForResourceAsync( string resourceName, IEnumerable<string> targetStates, CancellationToken cancellationToken = default(CancellationToken)) { // ... }}Parameters
resourceName string The name of the resource. targetStates IEnumerable<string> The set of states to wait for the resource to transition to one of. See KnownResourceStates for common states. cancellationToken CancellationToken optional A cancellation token that cancels the wait operation when signaled. Returns
Task<string> A Tasks.Task`1 representing the wait operation and which of the target states the resource reached. Remarks
cancellationToken is signaled, this method will throw OperationCanceledException. WaitForResourceAsync(string, Func<ResourceEvent, bool>, CancellationToken) Section titled WaitForResourceAsync(string, Func<ResourceEvent, bool>, CancellationToken) Task<ResourceEvent> public class ResourceNotificationService{ public Task<ResourceEvent> WaitForResourceAsync( string resourceName, Func<ResourceEvent, bool> predicate, CancellationToken cancellationToken = default(CancellationToken)) { // ... }}Parameters
resourceName string The name of the resource. predicate Func<ResourceEvent, bool> A predicate which is evaluated for each ResourceEvent for the selected resource. cancellationToken CancellationToken optional A cancellation token that cancels the wait operation when signaled. Returns
Task<ResourceEvent> A Tasks.Task`1 representing the wait operation and which of the target states the resource reached. Remarks
true. If the predicate isn't satisfied before cancellationToken is signaled, this method will throw OperationCanceledException. WaitForResourceHealthyAsync(string, CancellationToken) Section titled WaitForResourceHealthyAsync(string, CancellationToken) Task<ResourceEvent> public class ResourceNotificationService{ public Task<ResourceEvent> WaitForResourceHealthyAsync( string resourceName, CancellationToken cancellationToken = default(CancellationToken)) { // ... }}Parameters
resourceName string The name of the resource. cancellationToken CancellationToken optional The cancellation token. Returns
Task<ResourceEvent> A task. Remarks
This method returns a task that will complete with the resource is healthy. A resource without HealthCheckAnnotation annotations will be considered healthy once it reaches a KnownResourceStates.Running state.
If the resource enters an unavailable state such as KnownResourceStates.FailedToStart then this method will continue to wait to enable scenarios where a resource could be restarted and recover. To control this behavior use ResourceNotificationService.WaitForResourceHealthyAsync or configure the default behavior with ResourceNotificationServiceOptions.DefaultWaitBehavior.
WaitForResourceHealthyAsync(string, WaitBehavior, CancellationToken) Section titled WaitForResourceHealthyAsync(string, WaitBehavior, CancellationToken) Task<ResourceEvent> public class ResourceNotificationService{ public Task<ResourceEvent> WaitForResourceHealthyAsync( string resourceName, WaitBehavior waitBehavior, CancellationToken cancellationToken = default(CancellationToken)) { // ... }}Parameters
resourceName string The name of the resource. waitBehavior WaitBehavior The wait behavior. cancellationToken CancellationToken optional The cancellation token. Returns
Task<ResourceEvent> A task. Remarks
This method returns a task that will complete with the resource is healthy. A resource without HealthCheckAnnotation annotations will be considered healthy once it reaches a KnownResourceStates.Running state. The WaitBehavior controls how the wait operation behaves when the resource enters an unavailable state such as KnownResourceStates.FailedToStart.
When WaitBehavior.WaitOnResourceUnavailable is specified the wait operation will continue to wait until the resource reaches a KnownResourceStates.Running state.
When WaitBehavior.StopOnResourceUnavailable is specified the wait operation will throw a DistributedApplicationException if the resource enters an unavailable state.
WatchAsync(CancellationToken) Section titled WatchAsync(CancellationToken) IAsyncEnumerable<ResourceEvent> public class ResourceNotificationService{ public IAsyncEnumerable<ResourceEvent> WatchAsync( CancellationToken cancellationToken = default(CancellationToken)) { // ... }}Parameters
cancellationToken CancellationToken optional