|
1 | | -namespace Requests.Options |
| 1 | +namespace Requests.Options |
2 | 2 | { |
3 | 3 | /// <summary> |
4 | | - /// A record that implements the <see cref="IRequestOptions{TCompleted, TFailed}"/> interface. |
| 4 | + /// A record that implements the <see cref="IRequestOptions"/> interface. |
| 5 | + /// Provides configuration for request execution behavior. |
5 | 6 | /// </summary> |
6 | | - /// <typeparam name="TCompleted">The return type if the request is completed successfully.</typeparam> |
7 | | - /// <typeparam name="TFailed">The return type if the request fails.</typeparam> |
8 | | - public record RequestOptions<TCompleted, TFailed> : IRequestOptions<TCompleted, TFailed> |
| 7 | + public record RequestOptions : IRequestOptions |
9 | 8 | { |
10 | | - /// <inheritdoc /> |
11 | | - public bool AutoStart { get; set; } = true; |
12 | | - |
13 | | - ///<inheritdoc /> |
14 | | - public RequestPriority Priority { get; set; } = RequestPriority.Normal; |
15 | | - |
16 | | - ///<inheritdoc /> |
17 | | - public CancellationToken? CancellationToken { get; set; } |
18 | | - |
19 | | - ///<inheritdoc /> |
20 | | - public TimeSpan? DeployDelay { get; set; } = null; |
| 9 | + private IRequest? _subsequentRequest; |
21 | 10 |
|
22 | | - ///<inheritdoc /> |
23 | | - public IRequestHandler? Handler { get; set; } = ParallelRequestHandler.MainRequestHandler; |
24 | | - |
25 | | - ///<inheritdoc /> |
26 | | - public byte NumberOfAttempts { get; set; } = 3; |
27 | | - |
28 | | - ///<inheritdoc /> |
29 | | - public TimeSpan? DelayBetweenAttemps { get; set; } = null; |
| 11 | + /// <inheritdoc /> |
| 12 | + public bool AutoStart { get; init; } = true; |
30 | 13 |
|
31 | | - ///<inheritdoc /> |
32 | | - public IRequest? SubsequentRequest { get; set; } |
| 14 | + /// <inheritdoc /> |
| 15 | + public RequestPriority Priority { get; init; } = RequestPriority.Normal; |
33 | 16 |
|
34 | | - ///<inheritdoc /> |
35 | | - public Action<IRequest>? RequestStarted { get; set; } |
| 17 | + /// <inheritdoc /> |
| 18 | + public CancellationToken CancellationToken { get; init; } |
36 | 19 |
|
37 | | - ///<inheritdoc /> |
38 | | - public Action<IRequest, TCompleted>? RequestCompleted { get; set; } |
| 20 | + /// <inheritdoc /> |
| 21 | + public TimeSpan? DeployDelay { get; set; } |
39 | 22 |
|
40 | | - ///<inheritdoc /> |
41 | | - public Action<IRequest, TFailed>? RequestFailed { get; set; } |
| 23 | + /// <inheritdoc /> |
| 24 | + public IRequestHandler? Handler { get; init; } = ParallelRequestHandler.MainRequestHandler; |
42 | 25 |
|
43 | | - ///<inheritdoc /> |
44 | | - public Action<IRequest>? RequestCancelled { get; set; } |
| 26 | + /// <inheritdoc /> |
| 27 | + public byte NumberOfAttempts { get; init; } = 3; |
45 | 28 |
|
46 | | - ///<inheritdoc /> |
47 | | - public Action<IRequest, Exception>? RequestExceptionOccurred { get; set; } |
| 29 | + /// <inheritdoc /> |
| 30 | + public TimeSpan? DelayBetweenAttempts { get; init; } |
48 | 31 |
|
49 | | - /// <summary> |
50 | | - /// Copy constructor for the RequestOptions record. |
51 | | - /// </summary> |
52 | | - /// <param name="options">The RequestOptions instance to copy from.</param> |
53 | | - protected RequestOptions(RequestOptions<TCompleted, TFailed> options) |
| 32 | + /// <inheritdoc /> |
| 33 | + public IRequest? SubsequentRequest |
54 | 34 | { |
55 | | - Priority = options.Priority; |
56 | | - Handler = options.Handler; |
57 | | - NumberOfAttempts = options.NumberOfAttempts; |
58 | | - CancellationToken = options.CancellationToken; |
59 | | - AutoStart = options.AutoStart; |
60 | | - DelayBetweenAttemps = options.DelayBetweenAttemps; |
61 | | - DeployDelay = options.DeployDelay; |
62 | | - SubsequentRequest = options.SubsequentRequest; |
63 | | - RequestCancelled += options.RequestCancelled; |
64 | | - RequestStarted += options.RequestStarted; |
65 | | - RequestFailed += options.RequestFailed; |
66 | | - RequestCompleted += options.RequestCompleted; |
67 | | - RequestExceptionOccurred += options.RequestExceptionOccurred; |
| 35 | + get => _subsequentRequest; |
| 36 | + set |
| 37 | + { |
| 38 | + if (value?.HasCompleted() == true) |
| 39 | + throw new ArgumentException("Cannot set a completed request as subsequent request.", nameof(value)); |
| 40 | + |
| 41 | + _subsequentRequest = value; |
| 42 | + } |
68 | 43 | } |
69 | | - |
70 | | - /// <summary> |
71 | | - /// Default constructor for the RequestOptions record. |
72 | | - /// </summary> |
73 | | - public RequestOptions() { } |
74 | 44 | } |
75 | 45 | } |
0 commit comments