File tree Expand file tree Collapse file tree 1 file changed +22
-1
lines changed Expand file tree Collapse file tree 1 file changed +22
-1
lines changed Original file line number Diff line number Diff line change 6
6
using AngleSharp . Network . Default ;
7
7
using AngleSharp . Services ;
8
8
using System . Linq ;
9
+ using System . Net . Http ;
9
10
10
11
/// <summary>
11
12
/// Additional extensions for improved requesters.
@@ -28,5 +29,25 @@ public static IConfiguration WithRequesters(this IConfiguration configuration)
28
29
29
30
return configuration ;
30
31
}
32
+
33
+
34
+ /// <summary>
35
+ /// Adds a loader service that comes with all (improved) requesters.
36
+ /// </summary>
37
+ /// <param name="configuration">The configuration to use.</param>
38
+ /// <param name="httpMessageHandler">The HTTP handler stack to use for sending requests.</param>
39
+ /// <returns>The new configuration.</returns>
40
+ public static IConfiguration WithHttpRequesters ( this IConfiguration configuration , HttpMessageHandler httpMessageHandler )
41
+ {
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 ;
51
+ }
31
52
}
32
- }
53
+ }
You can’t perform that action at this time.
0 commit comments