Skip to content

Fallback

Alex edited this page Jan 29, 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 ment 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, the command will throw a FallbackNotImplementedException exception.

To enable for a command that returns a string.

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

Configuration - defaults

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