| | 1 | | // Copyright (c) ZeroC, Inc. |
| | 2 | |
|
| | 3 | | using IceRpc.Retry; |
| | 4 | | using Microsoft.Extensions.Logging; |
| | 5 | | using Microsoft.Extensions.Logging.Abstractions; |
| | 6 | |
|
| | 7 | | namespace IceRpc; |
| | 8 | |
|
| | 9 | | /// <summary>Provides extension methods for <see cref="Pipeline" /> to add the retry interceptor.</summary> |
| | 10 | | public static class RetryPipelineExtensions |
| | 11 | | { |
| | 12 | | /// <summary>Adds a <see cref="RetryInterceptor" /> that uses the default <see cref="RetryOptions" /> to the |
| | 13 | | /// pipeline.</summary> |
| | 14 | | /// <param name="pipeline">The pipeline being configured.</param> |
| | 15 | | /// <returns>The pipeline being configured.</returns> |
| | 16 | | /// <example> |
| | 17 | | /// The following code adds the retry interceptor using the default <see cref="RetryOptions"/> to the invocation |
| | 18 | | /// pipeline. |
| | 19 | | /// <code source="../../docfx/examples/IceRpc.Retry.Examples/RetryInterceptorExamples.cs" region="UseRetry" lang="cs |
| | 20 | | /// </example> |
| | 21 | | /// <seealso href="https://github.com/icerpc/icerpc-csharp/tree/main/examples/Retry"/> |
| | 22 | | public static Pipeline UseRetry(this Pipeline pipeline) => |
| 0 | 23 | | pipeline.UseRetry(new RetryOptions()); |
| | 24 | |
|
| | 25 | | /// <summary>Adds a <see cref="RetryInterceptor" /> to the pipeline.</summary> |
| | 26 | | /// <param name="pipeline">The pipeline being configured.</param> |
| | 27 | | /// <param name="options">The options to configure the <see cref="RetryInterceptor" />.</param> |
| | 28 | | /// <returns>The pipeline being configured.</returns> |
| | 29 | | /// <example> |
| | 30 | | /// The following code adds the retry interceptor using the provided <see cref="RetryOptions"/> to the invocation |
| | 31 | | /// pipeline. |
| | 32 | | /// <code source="../../docfx/examples/IceRpc.Retry.Examples/RetryInterceptorExamples.cs" region="UseRetryWithOption |
| | 33 | | /// </example> |
| | 34 | | /// <seealso href="https://github.com/icerpc/icerpc-csharp/tree/main/examples/Retry"/> |
| | 35 | | public static Pipeline UseRetry(this Pipeline pipeline, RetryOptions options) => |
| 0 | 36 | | pipeline.UseRetry(options, NullLoggerFactory.Instance); |
| | 37 | |
|
| | 38 | | /// <summary>Adds a <see cref="RetryInterceptor" /> to the pipeline.</summary> |
| | 39 | | /// <param name="pipeline">The pipeline being configured.</param> |
| | 40 | | /// <param name="options">The options to configure the <see cref="RetryInterceptor" />.</param> |
| | 41 | | /// <param name="loggerFactory">The logger factory used to create a <see cref="ILogger{TCategoryName}" /> for |
| | 42 | | /// <see cref="RetryInterceptor" />.</param> |
| | 43 | | /// <returns>The pipeline being configured.</returns> |
| | 44 | | /// <example> |
| | 45 | | /// The following code adds the retry interceptor using the provided <see cref="ILoggerFactory"/> and |
| | 46 | | /// <see cref="RetryOptions"/> to the invocation pipeline. |
| | 47 | | /// <code source="../../docfx/examples/IceRpc.Retry.Examples/RetryInterceptorExamples.cs" region="UseRetryWithLogger |
| | 48 | | /// </example> |
| | 49 | | /// <seealso href="https://github.com/icerpc/icerpc-csharp/tree/main/examples/Retry"/> |
| | 50 | | public static Pipeline UseRetry(this Pipeline pipeline, RetryOptions options, ILoggerFactory loggerFactory) => |
| 0 | 51 | | pipeline.Use(next => new RetryInterceptor(next, options, loggerFactory.CreateLogger<RetryInterceptor>())); |
| | 52 | | } |