-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathITaskFlowFactory.cs
More file actions
115 lines (115 loc) · 5.24 KB
/
Copy pathITaskFlowFactory.cs
File metadata and controls
115 lines (115 loc) · 5.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
namespace System.Threading.Tasks.Flow
{
/// <summary>
/// Defines a factory contract for creating <see cref="ITaskFlow"/> instances with optional naming support.
/// </summary>
/// <remarks>
/// <para>
/// The <see cref="ITaskFlowFactory"/> interface provides a standardized way to create task flow instances
/// within dependency injection containers. It supports named instances, allowing multiple task flow
/// configurations to coexist within the same application.
/// </para>
/// <para>
/// This factory interface is the primary entry point for creating task flows in dependency injection
/// scenarios. It abstracts the complexity of:
/// </para>
/// <list type="bullet">
/// <item>Named configuration resolution</item>
/// <item>Custom factory delegation</item>
/// <item>Option configuration</item>
/// <item>Scheduler chain configuration</item>
/// <item>Default factory fallback</item>
/// </list>
/// <para>
/// The factory supports multiple configuration patterns:
/// </para>
/// <list type="bullet">
/// <item><strong>Default instances</strong> - Created with default options when no name is specified</item>
/// <item><strong>Named instances</strong> - Created with specific configurations based on the provided name</item>
/// <item><strong>Custom factories</strong> - Delegate to user-provided factory implementations</item>
/// <item><strong>Chained schedulers</strong> - Apply scheduler wrapper chains for cross-cutting concerns</item>
/// </list>
/// </remarks>
/// <example>
/// <para>Basic factory usage in dependency injection:</para>
/// <code>
/// // Register TaskFlow services
/// services.AddTaskFlow();
///
/// // Inject and use the factory
/// public class SomeService
/// {
/// private readonly ITaskFlowFactory _taskFlowFactory;
///
/// public SomeService(ITaskFlowFactory taskFlowFactory)
/// {
/// _taskFlowFactory = taskFlowFactory;
/// }
///
/// public async Task ProcessDataAsync()
/// {
/// using var taskFlow = _taskFlowFactory.CreateTaskFlow();
/// await taskFlow.Enqueue(() => DoWorkAsync());
/// }
/// }
/// </code>
/// </example>
public interface ITaskFlowFactory
{
/// <summary>
/// Creates a new <see cref="ITaskFlow"/> instance with the specified name or default configuration.
/// </summary>
/// <param name="name">
/// The optional name identifying which configuration to use. If <c>null</c> or empty,
/// the default configuration is used.
/// </param>
/// <returns>
/// A new <see cref="ITaskFlow"/> instance configured according to the specified name or default settings.
/// </returns>
/// <remarks>
/// <para>
/// This method creates task flow instances based on the configuration associated with the provided name.
/// The factory resolves the configuration through the following precedence:
/// </para>
/// <list type="number">
/// <item><strong>Named factory</strong> - If a custom factory is registered for the name, it is used</item>
/// <item><strong>Default factory</strong> - If no named factory exists, the default factory is used</item>
/// <item><strong>Options configuration</strong> - Named options are applied if registered</item>
/// <item><strong>Scheduler chains</strong> - Named scheduler chains are applied if registered</item>
/// <item><strong>Fallback</strong> - Default options and configuration are used if nothing else is found</item>
/// </list>
/// <para>
/// The name parameter supports:
/// </para>
/// <list type="bullet">
/// <item><c>null</c> - Uses default configuration (equivalent to empty string)</item>
/// <item>Empty string - Uses default configuration</item>
/// <item>Named string - Uses configuration registered with that specific name</item>
/// </list>
/// <para>
/// Created task flows should be properly disposed when no longer needed to ensure
/// resource cleanup and proper shutdown of any background operations.
/// </para>
/// <para>
/// If multiple configurations are registered with the same name, the behavior depends
/// on the specific registration order and DI container implementation. Generally,
/// the last registered configuration takes precedence.
/// </para>
/// </remarks>
/// <example>
/// <code>
/// // Create default task flow
/// using var defaultFlow = factory.CreateTaskFlow();
///
/// // Create named task flow
/// using var namedFlow = factory.CreateTaskFlow("background-processor");
///
/// // Both are equivalent for default configuration
/// using var flow1 = factory.CreateTaskFlow(null);
/// using var flow2 = factory.CreateTaskFlow("");
/// using var flow3 = factory.CreateTaskFlow();
/// </code>
/// </example>
ITaskFlow CreateTaskFlow(string? name = null);
}
}