-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathDurableTaskWorkerBuilderExtensions.cs
More file actions
140 lines (130 loc) · 6.18 KB
/
DurableTaskWorkerBuilderExtensions.cs
File metadata and controls
140 lines (130 loc) · 6.18 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using Microsoft.DurableTask.Worker.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using static Microsoft.DurableTask.Worker.DurableTaskWorkerOptions;
namespace Microsoft.DurableTask.Worker;
/// <summary>
/// Extensions for <see cref="IDurableTaskWorkerBuilder" />.
/// </summary>
public static class DurableTaskWorkerBuilderExtensions
{
/// <summary>
/// Adds tasks to the current builder.
/// </summary>
/// <param name="builder">The builder to add tasks to.</param>
/// <param name="configure">The callback to add tasks.</param>
/// <returns>The original builder, for call chaining.</returns>
public static IDurableTaskWorkerBuilder AddTasks(
this IDurableTaskWorkerBuilder builder, Action<DurableTaskRegistry> configure)
{
Check.NotNull(builder);
builder.Services.Configure(builder.Name, configure);
return builder;
}
/// <summary>
/// Configures the worker options for this builder.
/// </summary>
/// <param name="builder">The builder to configure options for.</param>
/// <param name="configure">The configure callback.</param>
/// <returns>The original builder, for call chaining.</returns>
public static IDurableTaskWorkerBuilder Configure(
this IDurableTaskWorkerBuilder builder, Action<DurableTaskWorkerOptions> configure)
{
Check.NotNull(builder);
builder.Services.Configure(builder.Name, configure);
return builder;
}
/// <summary>
/// Sets the build target for this builder. This is the hosted service which will ultimately be ran on host
/// startup.
/// </summary>
/// <param name="builder">The builder to set the builder target for.</param>
/// <param name="target">The type of target to set.</param>
/// <returns>The original builder, for call chaining.</returns>
public static IDurableTaskWorkerBuilder UseBuildTarget(this IDurableTaskWorkerBuilder builder, Type target)
{
Check.NotNull(builder);
builder.BuildTarget = target;
return builder;
}
/// <summary>
/// Sets the build target for this builder. This is the hosted service which will ultimately be ran on host
/// startup.
/// </summary>
/// <typeparam name="TTarget">The builder target type.</typeparam>
/// <param name="builder">The builder to set the builder target for.</param>
/// <returns>The original builder, for call chaining.</returns>
public static IDurableTaskWorkerBuilder UseBuildTarget<TTarget>(this IDurableTaskWorkerBuilder builder)
where TTarget : DurableTaskWorker
=> builder.UseBuildTarget(typeof(TTarget));
/// <summary>
/// Sets the build target for this builder. This is the hosted service which will ultimately be ran on host
/// startup.
/// </summary>
/// <typeparam name="TTarget">The builder target type.</typeparam>
/// <typeparam name="TOptions">The options for this builder.</typeparam>
/// <param name="builder">The builder to set the builder target for.</param>
/// <returns>The original builder, for call chaining.</returns>
public static IDurableTaskWorkerBuilder UseBuildTarget<TTarget, TOptions>(this IDurableTaskWorkerBuilder builder)
where TTarget : DurableTaskWorker
where TOptions : DurableTaskWorkerOptions
{
builder.UseBuildTarget<TTarget>();
builder.Services.AddOptions<TOptions>(builder.Name)
.PostConfigure<IOptionsMonitor<DurableTaskWorkerOptions>>((options, baseOptions) =>
{
DurableTaskWorkerOptions input = baseOptions.Get(builder.Name);
input.ApplyTo(options);
});
return builder;
}
/// <summary>
/// Configures the versioning options for this builder.
/// </summary>
/// <param name="builder">The builder to set the builder target for.</param>
/// <param name="versionOptions">The collection of options specified for versioning the worker.</param>
/// <returns>The original builder, for call chaining.</returns>
public static IDurableTaskWorkerBuilder UseVersioning(this IDurableTaskWorkerBuilder builder, VersioningOptions versionOptions)
{
Check.NotNull(builder);
builder.Configure(options =>
{
options.Versioning = new VersioningOptions
{
Version = versionOptions.Version,
DefaultVersion = versionOptions.DefaultVersion,
MatchStrategy = versionOptions.MatchStrategy,
FailureStrategy = versionOptions.FailureStrategy,
};
});
return builder;
}
/// <summary>
/// Adds an orchestration filter to the specified <see cref="IDurableTaskWorkerBuilder"/>.
/// </summary>
/// <param name="builder">The builder to set the builder target for.</param>
/// <typeparam name="TOrchestrationFilter">The implementation of a <see cref="IOrchestrationFilter"/> that will be bound.</typeparam>
/// <returns>The same <see cref="IDurableTaskWorkerBuilder"/> instance, allowing for method chaining.</returns>
[Obsolete("Experimental")]
public static IDurableTaskWorkerBuilder UseOrchestrationFilter<TOrchestrationFilter>(this IDurableTaskWorkerBuilder builder) where TOrchestrationFilter : class, IOrchestrationFilter
{
Check.NotNull(builder);
builder.Services.AddSingleton<IOrchestrationFilter, TOrchestrationFilter>();
return builder;
}
/// <summary>
/// Adds an orchestration filter to the specified <see cref="IDurableTaskWorkerBuilder"/>.
/// </summary>
/// <param name="builder">The builder to set the builder target for.</param>
/// <param name="filter">The instance of an <see cref="IOrchestrationFilter"/> to use.</param>
/// <returns>The same <see cref="IDurableTaskWorkerBuilder"/> instance, allowing for method chaining.</returns>
[Obsolete("Experimental")]
public static IDurableTaskWorkerBuilder UseOrchestrationFilter(this IDurableTaskWorkerBuilder builder, IOrchestrationFilter filter)
{
Check.NotNull(builder);
builder.Services.AddSingleton(filter);
return builder;
}
}