@@ -47,9 +47,9 @@ internal HttpServerHostContextBuilder()
47
47
}
48
48
49
49
/// <summary>
50
- /// Gets or sets the Server Configuration object.
50
+ /// Gets the Server Configuration object.
51
51
/// </summary>
52
- public HttpServerConfiguration ServerConfiguration { get => _context . ServerConfiguration ; set => value = _context . ServerConfiguration ; }
52
+ public HttpServerConfiguration ServerConfiguration { get => _context . ServerConfiguration ; }
53
53
54
54
/// <summary>
55
55
/// Builds an <see cref="HttpServerHostContext"/> with the specified parameters.
@@ -63,9 +63,10 @@ public HttpServerHostContext Build()
63
63
/// Defines a function that will be executed immediately before starting the Http server.
64
64
/// </summary>
65
65
/// <param name="bootstrapAction">The action which will be executed before the Http server start.</param>
66
- public void UseBootstraper ( Action bootstrapAction )
66
+ public HttpServerHostContextBuilder UseBootstraper ( Action bootstrapAction )
67
67
{
68
- DefaultHttpServerHandler . _serverBootstraping = bootstrapAction ;
68
+ _context . HttpServer . handler . _default . _serverBootstraping = bootstrapAction ;
69
+ return this ;
69
70
}
70
71
71
72
/// <summary>
@@ -77,7 +78,7 @@ public void UseBootstraper(Action bootstrapAction)
77
78
/// call this method at the beginning of your builder, as the first immediate method.
78
79
/// </remarks>
79
80
/// <param name="portableConfigHandler">The handler of <see cref="PortableConfigurationBuilder"/>.</param>
80
- public void UsePortableConfiguration ( Action < PortableConfigurationBuilder > portableConfigHandler )
81
+ public HttpServerHostContextBuilder UsePortableConfiguration ( Action < PortableConfigurationBuilder > portableConfigHandler )
81
82
{
82
83
_portableConfiguration = new PortableConfigurationBuilder ( _context ) ;
83
84
try
@@ -107,90 +108,120 @@ public void UsePortableConfiguration(Action<PortableConfigurationBuilder> portab
107
108
}
108
109
Environment . Exit ( 2 ) ;
109
110
}
111
+ return this ;
110
112
}
111
113
112
114
/// <summary>
113
115
/// Sets the main <see cref="ListeningPort"/> of this host builder.
114
116
/// </summary>
115
117
/// <param name="port">The port the server will listen on.</param>
116
- public void UseListeningPort ( ushort port )
118
+ public HttpServerHostContextBuilder UseListeningPort ( ushort port )
117
119
{
118
120
_context . ServerConfiguration . ListeningHosts [ 0 ] . Ports [ 0 ] = new ListeningPort ( port ) ;
121
+ return this ;
119
122
}
120
123
121
124
/// <summary>
122
125
/// Sets the main <see cref="ListeningPort"/> of this host builder.
123
126
/// </summary>
124
127
/// <param name="uri">The URI component that will be parsed to the listening port format.</param>
125
- public void UseListeningPort ( string uri )
128
+ public HttpServerHostContextBuilder UseListeningPort ( string uri )
126
129
{
127
130
_context . ServerConfiguration . ListeningHosts [ 0 ] . Ports [ 0 ] = new ListeningPort ( uri ) ;
131
+ return this ;
128
132
}
129
133
130
134
/// <summary>
131
135
/// Sets the main <see cref="ListeningPort"/> of this host builder.
132
136
/// </summary>
133
137
/// <param name="listeningPort">The <see cref="ListeningPort"/> object which the Http server will listen to.</param>
134
- public void UseListeningPort ( ListeningPort listeningPort )
138
+ public HttpServerHostContextBuilder UseListeningPort ( ListeningPort listeningPort )
135
139
{
136
140
_context . ServerConfiguration . ListeningHosts [ 0 ] . Ports [ 0 ] = listeningPort ;
141
+ return this ;
137
142
}
138
143
139
144
/// <summary>
140
145
/// Overrides the <see cref="HttpServerConfiguration.DefaultCultureInfo"/> property in the HTTP server configuration.
141
146
/// </summary>
142
147
/// <param name="locale">The default <see cref="CultureInfo"/> object which the HTTP server will apply to the request handlers and callbacks thread.</param>
143
- public void UseLocale ( CultureInfo locale )
148
+ public HttpServerHostContextBuilder UseLocale ( CultureInfo locale )
144
149
{
145
150
_context . ServerConfiguration . DefaultCultureInfo = locale ;
151
+ return this ;
146
152
}
147
153
148
154
/// <summary>
149
155
/// Overrides the HTTP server flags with the provided flags.
150
156
/// </summary>
151
157
/// <param name="flags">The flags that will be set on the HTTP server.</param>
152
- public void UseFlags ( HttpServerFlags flags )
158
+ public HttpServerHostContextBuilder UseFlags ( HttpServerFlags flags )
153
159
{
154
160
_context . ServerConfiguration . Flags = flags ;
161
+ return this ;
155
162
}
156
163
157
164
/// <summary>
158
165
/// Calls an action that has the HTTP server configuration as an argument.
159
166
/// </summary>
160
167
/// <param name="handler">An action where the first argument is an <see cref="HttpServerConfiguration"/>.</param>
161
- public void UseConfiguration ( Action < HttpServerConfiguration > handler )
168
+ public HttpServerHostContextBuilder UseConfiguration ( Action < HttpServerConfiguration > handler )
162
169
{
163
170
handler ( _context . ServerConfiguration ) ;
171
+ return this ;
164
172
}
165
173
166
174
/// <summary>
167
175
/// Calls an action that has the HTTP server instance as an argument.
168
176
/// </summary>
169
177
/// <param name="handler">An action where the first argument is the main <see cref="HttpServer"/> object.</param>
170
- public void UseHttpServer ( Action < HttpServer > handler )
178
+ public HttpServerHostContextBuilder UseHttpServer ( Action < HttpServer > handler )
171
179
{
172
180
handler ( _context . HttpServer ) ;
181
+ return this ;
173
182
}
174
183
175
184
/// <summary>
176
185
/// Calls an action that has an <see cref="CrossOriginResourceSharingHeaders"/> instance from the main listening host as an argument.
177
186
/// </summary>
178
187
/// <param name="handler">An action where the first argument is the main <see cref="CrossOriginResourceSharingHeaders"/> object.</param>
179
- public void UseCors ( Action < CrossOriginResourceSharingHeaders > handler )
188
+ public HttpServerHostContextBuilder UseCors ( Action < CrossOriginResourceSharingHeaders > handler )
180
189
{
181
190
if ( _context . CrossOriginResourceSharingPolicy is null )
182
191
_context . CrossOriginResourceSharingPolicy = CrossOriginResourceSharingHeaders . Empty ;
183
192
184
193
handler ( _context . CrossOriginResourceSharingPolicy ) ;
194
+ return this ;
195
+ }
196
+
197
+ /// <summary>
198
+ /// Sets an <see cref="CrossOriginResourceSharingHeaders"/> instance in the current listening host.
199
+ /// </summary>
200
+ /// <param name="cors">The <see cref="CrossOriginResourceSharingHeaders"/> to the current host builder.</param>
201
+ public HttpServerHostContextBuilder UseCors ( CrossOriginResourceSharingHeaders cors )
202
+ {
203
+ _context . CrossOriginResourceSharingPolicy = cors ;
204
+ return this ;
185
205
}
186
206
187
207
/// <summary>
188
208
/// Calls an action that has an <see cref="Router"/> instance from the host HTTP server.
189
209
/// </summary>
190
210
/// <param name="handler">An action where the first argument is the main <see cref="Router"/> object.</param>
191
- public void UseRouter ( Action < Router > handler )
211
+ public HttpServerHostContextBuilder UseRouter ( Action < Router > handler )
212
+ {
213
+ _context . HttpServer . handler . _default . _routerSetup = handler ;
214
+ return this ;
215
+ }
216
+
217
+ /// <summary>
218
+ /// Sets an <see cref="Router"/> instance in the current listening host.
219
+ /// </summary>
220
+ /// <param name="r">The <see cref="Router"/> to the current host builder.</param>
221
+ public HttpServerHostContextBuilder UseRouter ( Router r )
192
222
{
193
- DefaultHttpServerHandler . _routerSetup = handler ;
223
+ _context . Router = r ;
224
+ return this ;
194
225
}
195
226
196
227
/// <summary>
@@ -199,9 +230,10 @@ public void UseRouter(Action<Router> handler)
199
230
/// <typeparam name="TModule">An class which implements <see cref="RouterModule"/>, or the router module itself.</typeparam>
200
231
/// <param name="activateInstances">Optional. Determines whether found types should be defined as instances or static members.</param>
201
232
[ RequiresUnreferencedCode ( SR . Router_AutoScanModules_RequiresUnreferencedCode ) ]
202
- public void UseAutoScan < TModule > ( bool activateInstances = true ) where TModule : RouterModule
233
+ public HttpServerHostContextBuilder UseAutoScan < TModule > ( bool activateInstances = true ) where TModule : RouterModule
203
234
{
204
235
_context . Router . AutoScanModules < TModule > ( typeof ( TModule ) . Assembly , activateInstances ) ;
236
+ return this ;
205
237
}
206
238
207
239
/// <summary>
@@ -211,26 +243,29 @@ public void UseAutoScan<TModule>(bool activateInstances = true) where TModule :
211
243
/// <param name="t">The assembly where the scanning types are.</param>
212
244
/// <param name="activateInstances">Optional. Determines whether found types should be defined as instances or static members.</param>
213
245
[ RequiresUnreferencedCode ( SR . Router_AutoScanModules_RequiresUnreferencedCode ) ]
214
- public void UseAutoScan < TModule > ( Assembly t , bool activateInstances = true ) where TModule : RouterModule
246
+ public HttpServerHostContextBuilder UseAutoScan < TModule > ( Assembly t , bool activateInstances = true ) where TModule : RouterModule
215
247
{
216
248
_context . Router . AutoScanModules < TModule > ( t , activateInstances ) ;
249
+ return this ;
217
250
}
218
251
219
252
/// <summary>
220
253
/// This method is an shortcut for calling <see cref="HttpServer.RegisterHandler{T}"/>.
221
254
/// </summary>
222
255
/// <typeparam name="THandler">The handler which implements <see cref="HttpServerHandler"/>.</typeparam>
223
- public void UseHandler < [ DynamicallyAccessedMembers ( DynamicallyAccessedMemberTypes . PublicMethods ) ] THandler > ( ) where THandler : HttpServerHandler , new ( )
256
+ public HttpServerHostContextBuilder UseHandler < THandler > ( ) where THandler : HttpServerHandler , new ( )
224
257
{
225
258
_context . HttpServer . RegisterHandler < THandler > ( ) ;
259
+ return this ;
226
260
}
227
261
228
262
/// <summary>
229
263
/// This method is an shortcut for calling <see cref="HttpServer.RegisterHandler"/>.
230
264
/// </summary>
231
265
/// <param name="handler">The instance of the server handler.</param>
232
- public void UseHandler ( HttpServerHandler handler )
266
+ public HttpServerHostContextBuilder UseHandler ( HttpServerHandler handler )
233
267
{
234
268
_context . HttpServer . RegisterHandler ( handler ) ;
269
+ return this ;
235
270
}
236
271
}
0 commit comments