Table of Contents

Class OptionalMediationExtensions

Namespace
Apizr.Optional.Extending
Assembly
Apizr.Integrations.Optional.dll

Optional request extensions

public static class OptionalMediationExtensions
Inheritance
OptionalMediationExtensions
Inherited Members

Methods

CatchAsync<TResult>(Task<Option<TResult, ApizrException<TResult>>>, Action<Exception>, bool)

Return TResult (from fetch or cache), no matter of exception (handled by onException). Could throw if you ask to with letThrowOnExceptionWithEmptyCache in case of exception with empty cache (onException won't be called), otherwise return the empty cache (have to be managed) after calling onException action.

public static Task<TResult> CatchAsync<TResult>(this Task<Option<TResult, ApizrException<TResult>>> option, Action<Exception> onException, bool letThrowOnExceptionWithEmptyCache = false)

Parameters

option Task<Option<TResult, ApizrException<TResult>>>
onException Action<Exception>

Action to call to handle exception (like informing the user) before returning result from cache

letThrowOnExceptionWithEmptyCache bool

True to let it throw the inner exception in case of empty cache, False to handle it with onException action and return empty cache result

Returns

Task<TResult>

Type Parameters

TResult

The returned result (from fetch if succeed or cache if failed)

OnResultAsync<TResult>(Task<Option<TResult, ApizrException<TResult>>>, Action<TResult>)

The action will be invoked just before throwing any exception that might have occurred during request execution

public static Task OnResultAsync<TResult>(this Task<Option<TResult, ApizrException<TResult>>> option, Action<TResult> onResult)

Parameters

option Task<Option<TResult, ApizrException<TResult>>>
onResult Action<TResult>

The action to invoke

Returns

Task

Type Parameters

TResult

The returned result (from fetch if succeed or cache if failed)

OnResultAsync<TResult>(Task<Option<TResult, ApizrException<TResult>>>, Func<TResult, ApizrException<TResult>, bool>)

The function will be invoked with the returned result and potential occurred exception. You might decide to throw from the function itself, or to return the success boolean.

public static Task<bool> OnResultAsync<TResult>(this Task<Option<TResult, ApizrException<TResult>>> option, Func<TResult, ApizrException<TResult>, bool> onResult)

Parameters

option Task<Option<TResult, ApizrException<TResult>>>
onResult Func<TResult, ApizrException<TResult>, bool>

The function to invoke

Returns

Task<bool>

Type Parameters

TResult

The returned result (from fetch if succeed or cache if failed)

OnResultAsync<TResult>(Task<Option<TResult, ApizrException<TResult>>>, Func<TResult, ApizrException<TResult>, Task<bool>>)

The function will be invoked with the returned result and potential occurred exception. Checking exception, you might decide to throw it from the function itself, or to return the success boolean.

public static Task<bool> OnResultAsync<TResult>(this Task<Option<TResult, ApizrException<TResult>>> option, Func<TResult, ApizrException<TResult>, Task<bool>> onResult)

Parameters

option Task<Option<TResult, ApizrException<TResult>>>
onResult Func<TResult, ApizrException<TResult>, Task<bool>>

The function to invoke

Returns

Task<bool>

Type Parameters

TResult

The returned result (from fetch if succeed or cache if failed)