Class ReferencedResource
- Namespace
- Acuit.Pinpoint.ResourceManagement
- Assembly
- Acuit.Pinpoint.ResourceManagement.Abstractions.dll
The base class for resources referenced by resource providers derived from ResourceProvider.
public abstract class ReferencedResource : IDisposable
- Inheritance
-
ReferencedResource
- Implements
- Derived
- Inherited Members
Remarks
To properly implement a derived class:
- Provide an implementation for the GetLastKnownValueAsync(CancellationToken) method.
- Call OnChanged() whenever the resource value changes.
UpdatingReferencedResource can be used to simplify implementing derived classes.
Constructors
ReferencedResource(Uri)
Initializes a new instance of the ReferencedResource class.
protected ReferencedResource(Uri url)
Parameters
url
UriThe resource URL.
Exceptions
- ArgumentNullException
url
is null.
Properties
Url
Gets the resource URL.
public Uri Url { get; }
Property Value
Methods
CreateNewReference()
Creates a new reference to this resource.
public IResourceReference CreateNewReference()
Returns
- IResourceReference
A new IResourceReference, which should be disposed when the reference is no longer needed to remove the reference.
Exceptions
- ObjectDisposedException
This object has been disposed.
Dispose()
Closes and releases all resources used by the object.
public void Dispose()
Dispose(bool)
Closes and releases all resources used by the ReferencedResource.
protected virtual void Dispose(bool disposing)
Parameters
Remarks
Derived classes should override this when they have any resources that should be disposed.
GetLastKnownValueAsync(CancellationToken)
Gets the last known value for this resource.
protected abstract Task<object> GetLastKnownValueAsync(CancellationToken cancellationToken)
Parameters
cancellationToken
CancellationTokenA cancellation token that can be used to request canceling waiting for the value.
Returns
- Task<object>
A task that represents the asynchronous operation. The value of its Result property contains the last known resource value.
Remarks
In general, this should immediately return the last known resource value, unless the initial asynchronous resource retrieval is still in progress, in which case
it should return a task that will complete when that attempt completes. Note that cancellationToken
will cancel waiting on that attempt to complete,
not cancel that attempt itself.
This might be called from multiple threads and before other asynchronous calls are complete.
Exceptions
- ObjectDisposedException
This object has been disposed.
- Exception
The resource could not be retrieved.
OnChanged()
Derived classes should call this to indicate that the resource value has changed.
protected void OnChanged()
Exceptions
- ObjectDisposedException
This object has been disposed.
Events
LastReferenceRemoved
Raised when the last reference for this resource is removed.
public event EventHandler LastReferenceRemoved