1
1
namespace AngleSharp
2
2
{
3
3
using AngleSharp . Io . Network ;
4
- using AngleSharp . Io . Services ;
5
4
using AngleSharp . Network ;
6
5
using AngleSharp . Network . Default ;
7
- using AngleSharp . Services ;
8
- using System . Linq ;
6
+ using AngleSharp . Services . Default ;
7
+ using System ;
9
8
using System . Net . Http ;
10
9
11
10
/// <summary>
@@ -17,37 +16,28 @@ public static class ConfigurationExtensions
17
16
/// Adds a loader service that comes with all (improved) requesters.
18
17
/// </summary>
19
18
/// <param name="configuration">The configuration to use.</param>
19
+ /// <param name="setup">Optional setup for the loader service.</param>
20
20
/// <returns>The new configuration.</returns>
21
- public static IConfiguration WithRequesters ( this IConfiguration configuration )
21
+ public static IConfiguration WithRequesters ( this IConfiguration configuration , Action < LoaderService > setup = null )
22
22
{
23
- if ( ! configuration . Services . OfType < ILoaderService > ( ) . Any ( ) )
24
- {
25
- var requesters = new IRequester [ ] { new HttpClientRequester ( ) , new DataRequester ( ) } ;
26
- var service = new LoaderService ( requesters ) ;
27
- return configuration . With ( service ) ;
28
- }
29
-
30
- return configuration ;
23
+ var requesters = new IRequester [ ] { new HttpClientRequester ( ) , new DataRequester ( ) } ;
24
+ return configuration . WithDefaultLoader ( setup , requesters ) ;
31
25
}
32
26
33
-
34
27
/// <summary>
35
28
/// Adds a loader service that comes with all (improved) requesters.
36
29
/// </summary>
37
30
/// <param name="configuration">The configuration to use.</param>
38
- /// <param name="httpMessageHandler">The HTTP handler stack to use for sending requests.</param>
31
+ /// <param name="httpMessageHandler">
32
+ /// The HTTP handler stack to use for sending requests.
33
+ /// </param>
34
+ /// <param name="setup">Optional setup for the loader service.</param>
39
35
/// <returns>The new configuration.</returns>
40
- public static IConfiguration WithHttpRequesters ( this IConfiguration configuration , HttpMessageHandler httpMessageHandler )
36
+ public static IConfiguration WithRequesters ( this IConfiguration configuration , HttpMessageHandler httpMessageHandler , Action < LoaderService > setup = null )
41
37
{
42
- if ( ! configuration . Services . OfType < ILoaderService > ( ) . Any ( ) )
43
- {
44
- var httpClient = new HttpClient ( httpMessageHandler ) ;
45
- var requesters = new IRequester [ ] { new HttpClientRequester ( httpClient ) , new DataRequester ( ) } ;
46
- var service = new LoaderService ( requesters ) ;
47
- return configuration . With ( service ) ;
48
- }
49
-
50
- return configuration ;
38
+ var httpClient = new HttpClient ( httpMessageHandler ) ;
39
+ var requesters = new IRequester [ ] { new HttpClientRequester ( httpClient ) , new DataRequester ( ) } ;
40
+ return configuration . WithDefaultLoader ( setup , requesters ) ;
51
41
}
52
42
}
53
43
}
0 commit comments