Skip to content

Configuration

Alex edited this page Jun 18, 2021 · 2 revisions

Most features can be configured and/or disabled through the configuration.
Configuration is injected in the constructor.

Example

class BasicCommand : ResilientCommand<string>
{
    public BasicCommand() : base(
        configuration: CommandConfiguration.CreateConfiguration(
            config => 
            {
                // all config is here.
            }))
    {
    }
    
    protected override Task<string> RunAsync(CancellationToken cancellationToken)
    {
        return Task.FromResult("MyCommand");
    }
}

Sometimes it might be preferable to disable certain features. There is a static class CommandConfigurationManager that can help you with this. Simply call GetCommandConfiguration() and give it the CommandKey of the command, you will get the instance of configuration it is running on.

public void DoStuff()
{
   var command = new BasicCommand(); // Default settings.

   CommandConfigurationManager.GetCommandConfiguration(command.CommandKey).FallbackSettings.IsEnabled = false;
   await command.ExecuteAsync(default); // Fallback will be disabled.
}
Clone this wiki locally