Skip to content

Fallback

Alex edited this page Feb 12, 2021 · 2 revisions

Disabled by default

The fallback can be thought of as a backup value in case of a failure from the dependency.
The idea is that the fallback will be returned and exceptions swallowed, not causing an outage.
A fallback can be enabled by overriding Fallback() which will cause any exceptions that are thrown to be handled and return the fallback value.
The fallback value is meant to be a static or at least local value.

Fallback can be disabled through configuration. If disabled, exceptions will fall through and bubble up.

Note: If Fallback() has not been overridden nor disabled, any exception thrown as part of the execution, will bubble up.

To enable for a command that returns a string.

protected override string Fallback()
{
    return "Some sane value.";
}

The fallback can also be used to fail silently.

protected override string Fallback()
{
    return null;
}

This would cause any exceptions to be swallowed and the command to simply return null.

Configuration - defaults

CommandConfiguration.CreateConfiguration(
config => 
{
    config.FallbackEnabled = true;
});
Clone this wiki locally