The end outcome is to shut down the application if a specific type of exception (DatabaseException
) has occurred.
However the current method HandleDatabaseException
does not stop the application, the execution will carry on. Even though the _applicationLifetime.Stop()
is executed.
private IHostApplicationLifetime _applicationLifetime;
public void CreatePolcy()
{
var policy = Policy
.Handle<DatabaseException>(ex => HandleDatabaseException(ex))
.WaitAndRetryForever(
retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)),
(exception, timespan) => HandleRetry(exception, timespan, stoppingToken));
}
public bool HandleDatabaseException(Exception ex)
{
_applicationLifetime.Stop();
return true;
}