/
DurableTaskJobHostConfigurationExtensions.cs
112 lines (99 loc) · 4.21 KB
/
DurableTaskJobHostConfigurationExtensions.cs
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
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.
using System;
#if NETSTANDARD2_0
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
#else
using Microsoft.Azure.WebJobs.Host;
using Microsoft.Azure.WebJobs.Host.Config;
#endif
namespace Microsoft.Azure.WebJobs.Extensions.DurableTask
{
/// <summary>
/// Extension for registering a Durable Functions configuration with <c>JobHostConfiguration</c>.
/// </summary>
public static class DurableTaskJobHostConfigurationExtensions
{
#if NETSTANDARD2_0
/// <summary>
/// Adds the Durable Task extension to the provided <see cref="IWebJobsBuilder"/>.
/// </summary>
/// <param name="builder">The <see cref="IWebJobsBuilder"/> to configure.</param>
/// <returns>Returns the provided <see cref="IWebJobsBuilder"/>.</returns>
public static IWebJobsBuilder AddDurableTask(this IWebJobsBuilder builder)
{
if (builder == null)
{
throw new ArgumentNullException(nameof(builder));
}
builder.AddExtension<DurableTaskExtension>()
.BindOptions<DurableTaskOptions>()
.Services.AddSingleton<IConnectionStringResolver, WebJobsConnectionStringProvider>();
return builder;
}
/// <summary>
/// Adds the Durable Task extension to the provided <see cref="IWebJobsBuilder"/>.
/// </summary>
/// <param name="builder">The <see cref="IWebJobsBuilder"/> to configure.</param>
/// <param name="options">The configuration options for this extension.</param>
/// <returns>Returns the provided <see cref="IWebJobsBuilder"/>.</returns>
public static IWebJobsBuilder AddDurableTask(this IWebJobsBuilder builder, IOptions<DurableTaskOptions> options)
{
if (builder == null)
{
throw new ArgumentNullException(nameof(builder));
}
if (options == null)
{
throw new ArgumentNullException(nameof(options));
}
builder.AddDurableTask();
builder.Services.AddSingleton(options);
return builder;
}
/// <summary>
/// Adds the Durable Task extension to the provided <see cref="IWebJobsBuilder"/>.
/// </summary>
/// <param name="builder">The <see cref="IWebJobsBuilder"/> to configure.</param>
/// <param name="configure">An <see cref="Action{DurableTaskOptions}"/> to configure the provided <see cref="DurableTaskOptions"/>.</param>
/// <returns>Returns the modified <paramref name="builder"/> object.</returns>
public static IWebJobsBuilder AddDurableTask(this IWebJobsBuilder builder, Action<DurableTaskOptions> configure)
{
if (builder == null)
{
throw new ArgumentNullException(nameof(builder));
}
if (configure == null)
{
throw new ArgumentNullException(nameof(configure));
}
builder.AddDurableTask();
builder.Services.Configure(configure);
return builder;
}
#else
/// <summary>
/// Enable running durable orchestrations implemented as functions.
/// </summary>
/// <param name="hostConfig">Configuration settings of the current <c>JobHost</c> instance.</param>
/// <param name="listenerConfig">Durable Functions configuration.</param>
public static void UseDurableTask(
this JobHostConfiguration hostConfig,
DurableTaskExtension listenerConfig)
{
if (hostConfig == null)
{
throw new ArgumentNullException(nameof(hostConfig));
}
if (listenerConfig == null)
{
throw new ArgumentNullException(nameof(listenerConfig));
}
IExtensionRegistry extensions = hostConfig.GetService<IExtensionRegistry>();
extensions.RegisterExtension<IExtensionConfigProvider>(listenerConfig);
}
#endif
}
}