| | 1 | | // Copyright (c) ZeroC, Inc. |
| | 2 | |
|
| | 3 | | using IceRpc.Retry; |
| | 4 | | using Microsoft.Extensions.Logging; |
| | 5 | |
|
| | 6 | | namespace IceRpc.Extensions.DependencyInjection; |
| | 7 | |
|
| | 8 | | /// <summary>Provides extension methods for <see cref="IInvokerBuilder" /> to add the retry interceptor.</summary> |
| | 9 | | public static class RetryInvokerBuilderExtensions |
| | 10 | | { |
| | 11 | | /// <summary>Adds a <see cref="RetryInterceptor" /> that uses the default <see cref="RetryOptions" />.</summary> |
| | 12 | | /// <param name="builder">The pipeline being configured.</param> |
| | 13 | | /// <returns>The pipeline being configured.</returns> |
| | 14 | | public static IInvokerBuilder UseRetry(this IInvokerBuilder builder) => |
| 0 | 15 | | builder.UseRetry(new RetryOptions()); |
| | 16 | |
|
| | 17 | | /// <summary>Adds a <see cref="RetryInterceptor" /> to the builder. This interceptor relies on the |
| | 18 | | /// <see cref="ILogger{T}" /> service managed by the service provider.</summary> |
| | 19 | | /// <param name="builder">The builder being configured.</param> |
| | 20 | | /// <param name="options">The options to configure the <see cref="RetryInterceptor" />.</param> |
| | 21 | | /// <returns>The builder being configured.</returns> |
| | 22 | | public static IInvokerBuilder UseRetry(this IInvokerBuilder builder, RetryOptions options) => |
| 0 | 23 | | builder.ServiceProvider.GetService(typeof(ILogger<RetryInterceptor>)) is ILogger logger ? |
| 0 | 24 | | builder.Use(next => new RetryInterceptor(next, options, logger)) : |
| 0 | 25 | | throw new InvalidOperationException( |
| 0 | 26 | | $"Could not find service of type '{nameof(ILogger<RetryInterceptor>)}' in the service container."); |
| | 27 | | } |