Table of Contents

Class EndpointOptions<TArg, TResult>

Namespace
Phetch.Core
Assembly
Phetch.Core.dll

Options that are passed to an Endpoint.

public sealed record EndpointOptions<TArg, TResult> : IEquatable<EndpointOptions<TArg, TResult>>

Type Parameters

TArg
TResult
Inheritance
EndpointOptions<TArg, TResult>
Implements
IEquatable<EndpointOptions<TArg, TResult>>
Inherited Members

Constructors

EndpointOptions()

Options that are passed to an Endpoint.

public EndpointOptions()

EndpointOptions(EndpointOptions)

Creates a strongly-typed EndpointOptions<TArg, TResult> from an EndpointOptions instance.

public EndpointOptions(EndpointOptions original)

Parameters

original EndpointOptions

Properties

CacheTime

The amount of time to store query results in the cache after they stop being used.

public TimeSpan CacheTime { get; init; }

Property Value

TimeSpan

Remarks

When set to Zero, queries will be removed from the cache as soon as they have no observers.

When set to MaxValue, queries will never be removed from the cache.

Default

An instance of EndpointOptions<TArg, TResult> with default values.

public static EndpointOptions<TArg, TResult> Default { get; }

Property Value

EndpointOptions<TArg, TResult>

DefaultStaleTime

Default stale time to be used if not supplied when using the endpoint. This defaults to zero, so queries are considered stale as soon as they finish fetching.

When set to MaxValue, queries will never be considered stale (unless they are manually invalidated).
public TimeSpan DefaultStaleTime { get; init; }

Property Value

TimeSpan

Remarks

This can be overridden by StaleTime

KeySelector

A function that can be used to override the default behavior for determining which query arguments are the same. The object returned by this function will be used as the dictionary keys for the query cache. This is useful if your query argument type is not suitable to use a dictionary key, because it doesn't implement GetHashCode and Equals.

If not provided, the query arguments are used as dictionary keys directly.
public Func<TArg, object>? KeySelector { get; init; }

Property Value

Func<TArg, object>

Remarks

In many cases, the best way to use this is by returning a tuple of all relevant fields:

KeySelector = arg => (arg.Id, arg.Name)

OnFailure

A function that gets run whenever this query fails.

public Action<QueryFailureEventArgs<TArg>>? OnFailure { get; init; }

Property Value

Action<QueryFailureEventArgs<TArg>>

Remarks

Unlike OnFailure, this will be called even if the query is not being observed.

OnSuccess

A function that gets run whenever this query succeeds.

public Action<QuerySuccessEventArgs<TArg, TResult>>? OnSuccess { get; init; }

Property Value

Action<QuerySuccessEventArgs<TArg, TResult>>

Remarks

Unlike OnSuccess, this will be called exactly once per successful invokation of the underlying query function. This means:

RetryHandler

An optional object to control whether and how the query function is retried if it fails. If left null, the query will not be retried when it fails.

public IRetryHandler? RetryHandler { get; init; }

Property Value

IRetryHandler

Remarks

Example:
var endpoint = new Endpoint<int, string>(..., new() {
      RetryHandler = RetryHandler.Simple(3)
  });

Operators

implicit operator EndpointOptions<TArg, TResult>(EndpointOptions)

Converts an untyped EndpointOptions instance into an EndpointOptions<TArg, TResult>.

public static implicit operator EndpointOptions<TArg, TResult>(EndpointOptions original)

Parameters

original EndpointOptions

Returns

EndpointOptions<TArg, TResult>