Skip to content

Commit 812d121

Browse files
authored
docs: add example of adding a WebProxy using DI (#1181)
Adds example of configuring a WebProxy when using the DI project.
1 parent 8d1e10a commit 812d121

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

README.md

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -185,15 +185,6 @@ class Program
185185
}
186186
```
187187

188-
<a name="proxy"></a>
189-
## Web Proxy
190-
191-
```csharp
192-
var apiKey = Environment.GetEnvironmentVariable("SENDGRID_API_KEY");
193-
var proxy = new WebProxy("http://proxy:1337");
194-
var client = new SendGridClient(proxy, apiKey);
195-
```
196-
197188
## HttpClientFactory + Microsoft.Extensions.DependencyInjection
198189

199190
> [SendGrid.Extensions.DependencyInjection](https://www.nuget.org/packages/SendGrid.Extensions.DependencyInjection) is required
@@ -234,6 +225,30 @@ class Program
234225
}
235226
```
236227

228+
<a name="proxy"></a>
229+
## Web Proxy
230+
231+
```csharp
232+
var apiKey = Environment.GetEnvironmentVariable("SENDGRID_API_KEY");
233+
var proxy = new WebProxy("http://proxy:1337");
234+
var client = new SendGridClient(proxy, apiKey);
235+
```
236+
237+
Or when using DependencyInjection
238+
239+
```csharp
240+
services.AddSendGrid(options =>
241+
{
242+
options.ApiKey = Environment.GetEnvironmentVariable("SENDGRID_API_KEY");
243+
})
244+
.ConfigurePrimaryHttpMessageHandler(_ => new HttpClientHandler()
245+
{
246+
Proxy = new WebProxy(new Uri("http://proxy:1337")),
247+
UseProxy = true
248+
});
249+
```
250+
251+
237252
# Usage
238253

239254
- [Twilio SendGrid Docs](https://docs.sendgrid.com/api-reference/)

0 commit comments

Comments
 (0)