As @PanagiotisKanavos already pointed out, Pomelo already has connection resiliency support.
The simplest way to use it, is to enable the default strategy:
dbContextOptions.UseMySql(
connectionString,
serverVersion,
mySqlOptions => mySqlOptions.EnableRetryOnFailure())
It will retry up to six times, incrementally waiting for longer periods between retries (but not longer than 30 seconds).
If you want to configure the retry strategy, use the following overload instead:
dbContextOptions.UseMySql(
connectionString,
serverVersion,
mySqlOptions => mySqlOptions
.EnableRetryOnFailure(
maxRetryCount: 3,
maxRetryDelay: TimeSpan.FromSeconds(15),
errorNumbersToAdd: null))
If you want full control over all aspects of the execution strategy, you can inject your own implementation (that either inherits from MySqlExecutionStrategy
or directly implements IExecutionStrategy
):
dbContextOptions.UseMySql(
connectionString,
serverVersion,
mySqlOptions => mySqlOptions
.ExecutionStrategy(dependencies => new YourExecutionStrategy(dependencies))