| | 1 | | // Copyright (c) ZeroC, Inc. |
| | 2 | |
|
| | 3 | | using IceRpc.Deadline; |
| | 4 | |
|
| | 5 | | namespace IceRpc.Extensions.DependencyInjection; |
| | 6 | |
|
| | 7 | | /// <summary>Provides extension methods for <see cref="IInvokerBuilder" /> to add the deadline interceptor.</summary> |
| | 8 | | public static class DeadlineInvokerBuilderExtensions |
| | 9 | | { |
| | 10 | | /// <summary>Adds a <see cref="DeadlineInterceptor" /> with an infinite default timeout to this invoker builder. |
| | 11 | | /// This interceptor enforces the deadlines it receives and does not create new deadlines.</summary> |
| | 12 | | /// <param name="builder">The builder being configured.</param> |
| | 13 | | /// <returns>The builder being configured.</returns> |
| | 14 | | public static IInvokerBuilder UseDeadline(this IInvokerBuilder builder) => |
| 0 | 15 | | builder.UseDeadline(Timeout.InfiniteTimeSpan); |
| | 16 | |
|
| | 17 | | /// <summary>Adds a <see cref="DeadlineInterceptor" /> to this invoker builder.</summary> |
| | 18 | | /// <param name="builder">The builder being configured.</param> |
| | 19 | | /// <param name="defaultTimeout">The default timeout. When not infinite, the interceptor adds a deadline to requests |
| | 20 | | /// without a deadline.</param> |
| | 21 | | /// <param name="alwaysEnforceDeadline">When <see langword="true" /> and the request carries a deadline, the |
| | 22 | | /// interceptor always creates a cancellation token source to enforce this deadline. When <see langword="false" /> |
| | 23 | | /// and the request carries a deadline, the interceptor creates a cancellation token source to enforce this deadline |
| | 24 | | /// only when the invocation's cancellation token cannot be canceled. The default value is <see langword="false" />. |
| | 25 | | /// </param> |
| | 26 | | /// <returns>The builder being configured.</returns> |
| | 27 | | public static IInvokerBuilder UseDeadline( |
| | 28 | | this IInvokerBuilder builder, |
| | 29 | | TimeSpan defaultTimeout, |
| | 30 | | bool alwaysEnforceDeadline = false) => |
| 0 | 31 | | builder.Use(next => new DeadlineInterceptor(next, defaultTimeout, alwaysEnforceDeadline)); |
| | 32 | | } |