-
Notifications
You must be signed in to change notification settings - Fork 1
/
HostBuilderExtensions.Client.cs
162 lines (152 loc) · 6.29 KB
/
HostBuilderExtensions.Client.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
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
// Copyright (c) Escendit Ltd. All Rights Reserved.
// Licensed under the MIT. See LICENSE.txt file in the solution root for full license information.
namespace Microsoft.Extensions.Hosting;
using DependencyInjection;
using Escendit.Extensions.Hosting.Cassandra;
using Options;
/// <summary>
/// Host Builder Extensions.
/// </summary>
public static partial class HostBuilderExtensions
{
/// <summary>
/// Add Cassandra Client As Default.
/// </summary>
/// <param name="hostBuilder">The initial host builder.</param>
/// <param name="configureOptions">The configure options.</param>
/// <returns>The updated host builder.</returns>
public static IHostBuilder AddCassandraClientAsDefault(
this IHostBuilder hostBuilder,
Action<CassandraClientOptions> configureOptions)
{
ArgumentNullException.ThrowIfNull(hostBuilder);
ArgumentNullException.ThrowIfNull(configureOptions);
return hostBuilder
.ConfigureServices(services => services
.AddCassandraClientAsDefault(configureOptions));
}
/// <summary>
/// Add Cassandra Client As Default.
/// </summary>
/// <param name="hostBuilder">The initial host builder.</param>
/// <param name="configureOptions">The configure options.</param>
/// <returns>The updated host builder.</returns>
public static IHostBuilder AddCassandraClientAsDefault(
this IHostBuilder hostBuilder,
Action<OptionsBuilder<CassandraClientOptions>> configureOptions)
{
ArgumentNullException.ThrowIfNull(hostBuilder);
ArgumentNullException.ThrowIfNull(configureOptions);
return hostBuilder
.ConfigureServices(services => services
.AddCassandraClientAsDefault(configureOptions));
}
/// <summary>
/// Add Cassandra Client As Default.
/// </summary>
/// <param name="hostBuilder">The initial host builder.</param>
/// <param name="configSectionPrefix">The config section prefix.</param>
/// <returns>The updated host builder.</returns>
public static IHostBuilder AddCassandraClientAsDefault(
this IHostBuilder hostBuilder,
string configSectionPrefix = OptionsDefaults.ClientKey)
{
ArgumentNullException.ThrowIfNull(hostBuilder);
ArgumentNullException.ThrowIfNull(configSectionPrefix);
return hostBuilder
.AddCassandraClientAsDefault(options => options
.BindConfiguration($"{configSectionPrefix}:{options.Name}"));
}
/// <summary>
/// Add Cassandra Client.
/// </summary>
/// <param name="hostBuilder">The initial host builder.</param>
/// <param name="name">The name.</param>
/// <param name="configureOptions">The configure options.</param>
/// <returns>The updated host builder.</returns>
public static IHostBuilder AddCassandraClient(
this IHostBuilder hostBuilder,
string name,
Action<CassandraClientOptions> configureOptions)
{
ArgumentNullException.ThrowIfNull(hostBuilder);
ArgumentNullException.ThrowIfNull(name);
ArgumentNullException.ThrowIfNull(configureOptions);
return hostBuilder
.ConfigureServices(services => services
.AddCassandraClient(name, configureOptions));
}
/// <summary>
/// Add Cassandra Client.
/// </summary>
/// <param name="hostBuilder">The initial host builder.</param>
/// <param name="name">The name.</param>
/// <param name="configureOptions">The configure options.</param>
/// <returns>The updated host builder.</returns>
public static IHostBuilder AddCassandraClient(
this IHostBuilder hostBuilder,
string name,
Action<OptionsBuilder<CassandraClientOptions>> configureOptions)
{
ArgumentNullException.ThrowIfNull(hostBuilder);
ArgumentNullException.ThrowIfNull(name);
ArgumentNullException.ThrowIfNull(configureOptions);
return hostBuilder
.ConfigureServices(services => services
.AddCassandraClient(name, configureOptions));
}
/// <summary>
/// Add Cassandra Client.
/// </summary>
/// <param name="hostBuilder">The initial host builder.</param>
/// <param name="name">The name.</param>
/// <param name="configSectionPrefix">The config section prefix.</param>
/// <returns>The updated host builder.</returns>
public static IHostBuilder AddCassandraClient(
this IHostBuilder hostBuilder,
string name,
string configSectionPrefix = OptionsDefaults.ClientKey)
{
ArgumentNullException.ThrowIfNull(hostBuilder);
ArgumentNullException.ThrowIfNull(name);
ArgumentNullException.ThrowIfNull(configSectionPrefix);
return hostBuilder
.AddCassandraClient(name, options => options
.BindConfiguration($"{configSectionPrefix}:{options.Name}"));
}
/// <summary>
/// Add Cassandra Client From Options As Default..
/// </summary>
/// <param name="hostBuilder">The initial host builder.</param>
/// <param name="optionsName">The options name.</param>
/// <returns>The updated host builder.</returns>
public static IHostBuilder AddCassandraClientFromOptionsAsDefault(
this IHostBuilder hostBuilder,
string optionsName)
{
ArgumentNullException.ThrowIfNull(hostBuilder);
ArgumentNullException.ThrowIfNull(optionsName);
return hostBuilder
.ConfigureServices(services => services
.AddCassandraClientFromOptionsAsDefault(optionsName));
}
/// <summary>
/// Add Cassandra Client From Options.
/// </summary>
/// <param name="hostBuilder">The initial host builder.</param>
/// <param name="name">The name.</param>
/// <param name="optionsName">The options name.</param>
/// <returns>The updated host builder.</returns>
public static IHostBuilder AddCassandraClientFromOptions(
this IHostBuilder hostBuilder,
string name,
string optionsName)
{
ArgumentNullException.ThrowIfNull(hostBuilder);
ArgumentNullException.ThrowIfNull(name);
ArgumentNullException.ThrowIfNull(optionsName);
return hostBuilder
.ConfigureServices(services => services
.AddCassandraClientFromOptions(name, optionsName));
}
}