Interface IOptionsAccessor<TOptions>
- Namespace
- Acuit.Pinpoint.Workstation.Configuration
- Assembly
- Acuit.Pinpoint.Workstation.Abstractions.dll
An accessor for a set of options tracked by an IOptionsRegistry options registry.
public interface IOptionsAccessor<TOptions> where TOptions : class
Type Parameters
TOptionsThe options instance type.
- Extension Methods
Properties
Name
Gets the name optionally used to register the options, or null if none was specified.
string? Name { get; }
Property Value
Value
Gets the current options value.
TOptions Value { get; }
Property Value
- TOptions
Remarks
This will never be null. Before options have been loaded, or when there is an error binding the configuration setting values to the
TOptions object, this will be set to a default set of options (i.e., an instance constructed via
CreateInstance(IServiceProvider, Type, params object[])).
These options may be invalid (i.e., they fail data annotations validation). Implementations or clients can validate options via TryValidateObject(object, ICollection<ValidationResult>?).
Methods
GetValueAsync(CancellationToken)
Gets the options value, waiting for any pending options update to complete.
Task<TOptions> GetValueAsync(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationTokenA token that can request cancellation.
Returns
- Task<TOptions>
The task object representing the asynchronous operation.
Remarks
Once the operation completes, the Result property on the returned task object contains the options value.
If the options are being updated due to a change in the source configuration settings, this will asynchronously wait for the update to complete, including any validation and/or initialization via IInitializableOptions, before completing with the updated options. If, while the options update was occurring, another change in the source configuration settings occurs, this will wait for the subsequent update before completing.
This will never be null. If the options type has not yet been registered, or when there is an error binding the configuration setting
values to the TOptions object, this will be set to a default set of options (i.e., an instance constructed via
CreateInstance(IServiceProvider, Type, params object[])).
These options may be invalid (i.e., they fail data annotations validation). Implementations or clients can validate options via TryValidateObject(object, ICollection<ValidationResult>?).
RegisterOptionsWatcherAsync(Func<Task>, OptionsWatcherOptions, int)
Registers an options watcher.
Task<IDisposable> RegisterOptionsWatcherAsync(Func<Task> callback, OptionsWatcherOptions options = OptionsWatcherOptions.None, int priority = 0)
Parameters
callbackFunc<Task>The asynchronous callback.
optionsOptionsWatcherOptionsOptions for the options watcher registration.
priorityintThe watcher priority. Higher values indicate higher priority.
Returns
- Task<IDisposable>
The task object representing the asynchronous operation.
Remarks
Once the operation completes, the Result property on the returned task object contains a IDisposable that can be used to unregister the watcher.
Registered watchers will be called in order of descending priority, and then in the order they were registered. Callbacks will always be invoked from the main application dispatcher thread.
See OptionsWatcherOptions for descriptions of how options affects the behavior of this method.
Exceptions
- ArgumentNullException
callbackis null.