/// <summary> /// Create a new instance of the <see cref="T:Microsoft.Practices.EnterpriseLibrary.TransientFaultHandling.RetryPolicy" /> class with the specified retry strategy. /// </summary> /// <param name="retryStrategy">The retry strategy.</param> /// <param name="isTransient">The predicate function to detect whether the specified exception is transient.</param> /// <typeparam name="TException">The type of the transient exception.</typeparam> /// <returns>A new instance of the <see cref="T:Microsoft.Practices.EnterpriseLibrary.TransientFaultHandling.RetryPolicy" /> class.</returns> public static RetryPolicy Catch <TException>( this RetryStrategy retryStrategy, Func <TException, bool>?isTransient = null) where TException : Exception => CreateRetryPolicy( retryStrategy.NotNull(), isTransient is null ? exception => exception is TException : exception => exception is TException specifiedException && isTransient(specifiedException));
public static async Task <int> SaveChangesAsync( this DbContext context, Func <IEnumerable <DbEntityEntry>, Task> resolveConflictsAsync, RetryStrategy retryStrategy) { context.NotNull(nameof(context)); resolveConflictsAsync.NotNull(nameof(resolveConflictsAsync)); retryStrategy.NotNull(nameof(retryStrategy)); RetryPolicy retryPolicy = new RetryPolicy( new TransientDetection <DbUpdateConcurrencyException>(), retryStrategy); retryPolicy.Retrying += (sender, e) => resolveConflictsAsync(((DbUpdateConcurrencyException)e.LastException).Entries).Wait(); return(await retryPolicy.ExecuteAsync(async() => await context.SaveChangesAsync())); }
/// <summary> /// Create a new instance of the <see cref="T:Microsoft.Practices.EnterpriseLibrary.TransientFaultHandling.RetryPolicy" /> class with the specified retry strategy. /// </summary> /// <param name="retryStrategy">The retry strategy.</param> /// <param name="isTransient">The predicate function to detect whether the specified exception is transient.</param> /// <returns>A new instance of the <see cref="T:Microsoft.Practices.EnterpriseLibrary.TransientFaultHandling.RetryPolicy" /> class.</returns> public static RetryPolicy Catch(this RetryStrategy retryStrategy, Func <Exception, bool>?isTransient = null) => CreateRetryPolicy(retryStrategy.NotNull(), isTransient);