-
Notifications
You must be signed in to change notification settings - Fork 3
/
Program.cs
27 lines (19 loc) · 867 Bytes
/
Program.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
using Ae.Dns.Client;
using Ae.Dns.Protocol;
using Microsoft.Extensions.DependencyInjection;
using System.Net;
// Create a DI container
IServiceCollection services = new ServiceCollection();
// Add any IDnsClient implementation to it
services.AddSingleton<IDnsClient>(new DnsUdpClient(IPAddress.Parse("1.1.1.1")));
// Add the DelegatingHandler
services.AddTransient<DnsDelegatingHandler>();
// Set up your HTTP client class
services.AddHttpClient<IMyTypedClient, MyTypedClient>()
.AddHttpMessageHandler<DnsDelegatingHandler>();
// Build the service provider
IServiceProvider provider = services.BuildServiceProvider();
// Retrieve the HTTP client implementation
IMyTypedClient myTypedClient = provider.GetRequiredService<IMyTypedClient>();
var response = await myTypedClient.GetGoogle(CancellationToken.None);
Console.WriteLine(response.StatusCode);