A discussion with @NickCraver produced some ideas about how to add support for "wrapper" packages that customize library behavior by automatically setting various configuration options. The goal here is to make the user experience as simple as possible, so they can apply a wrapper package with minimal changes to existing code. I'll list some options below - please take a look and share your thoughts.
Pass a "tuner" action to on a call to .Connect()
Usage:
var connection = ConnectionMultiplexer.Connect("cachename", CustomRedis.OptimizeForScenario(recoverLostConnections: true), logWriter);
Enabled via new overloads of Connect*() methods that take an additional Action<ConfigurationOptions> parameter:
public static ConnectionMultiplexer Connect(string configuration, Action<ConfigurationOptions> configurationTuner, TextWriter log = null)
Implementation of a "tuner" method in a wrapper package would look like:
public static Action<ConfigurationOptions> OptimizeForScenario(bool recoverLostConnections = true)
{
return (ConfigurationOptions configurationOptions) =>
{
configurationOptions.AbortOnConnectFail = !recoverLostConnections;
// etc.
};
}
Apply a "tuner" action to a ConfigurationOptions instance
Usage:
var options = new ConfigurationOptions()
{
EndPoints = { "cachename" },
};
options.Apply(CustomRedis.OptimizeForScenario(recoverLostConnections: true));
var connection = ConnectionMultiplexer.Connect(options);
Enabled via a new method added to ConfigurationOptions with a signature like:
public ConfigurationOptions Apply(Action<ConfigurationOptions> tuner)
A discussion with @NickCraver produced some ideas about how to add support for "wrapper" packages that customize library behavior by automatically setting various configuration options. The goal here is to make the user experience as simple as possible, so they can apply a wrapper package with minimal changes to existing code. I'll list some options below - please take a look and share your thoughts.
Pass a "tuner" action to on a call to .Connect()
Usage:
Enabled via new overloads of Connect*() methods that take an additional
Action<ConfigurationOptions>parameter:Implementation of a "tuner" method in a wrapper package would look like:
Apply a "tuner" action to a ConfigurationOptions instance
Usage:
Enabled via a new method added to
ConfigurationOptionswith a signature like: