You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For scenarios where client configurations are not known at startup (e.g., desktop applications where users add accounts at runtime), use dynamic client creation:
> Failing to dispose dynamic clients will leak `HttpClient` instances and their underlying socket connections. Always use a `using` statement or explicitly call `Dispose()`.
286
+
215
287
## Environment Variables
216
288
217
289
Configuration can also be provided via environment variables using the `__` (double underscore) convention:
1.**Dependency Injection** (recommended for most applications) - Register clients at startup with `AddCloudflareApiClient()`
47
+
2.**Dynamic Creation** - Create clients at runtime when configurations aren't known at startup (see [Dynamic Clients](#option-2-dynamic-clients-runtime-creation))
48
+
49
+
### Dependency Injection
50
+
51
+
Register the clients in your `Program.cs`:
52
+
53
+
```csharp
54
+
varbuilder=WebApplication.CreateBuilder(args);
55
+
56
+
// Register from IConfiguration (binds to "Cloudflare" and "R2" sections)
options.RateLimiting.EnableProactiveThrottling=true; // Delay requests when quota is low
74
+
options.RateLimiting.QuotaLowThreshold=0.1; // Throttle at 10% remaining
75
+
});
76
+
```
77
+
44
78
### appsettings.json
45
79
46
80
Configure your Cloudflare credentials in `appsettings.json`:
@@ -73,35 +107,6 @@ Configure your Cloudflare credentials in `appsettings.json`:
73
107
> [!NOTE]
74
108
> Never commit API tokens or secrets to source control. Use [User Secrets](https://learn.microsoft.com/en-us/aspnet/core/security/app-secrets) for development and environment variables or a managed Key Vault for production.
75
109
76
-
### Dependency Injection
77
-
78
-
Register the clients in your `Program.cs`:
79
-
80
-
```csharp
81
-
varbuilder=WebApplication.CreateBuilder(args);
82
-
83
-
// Register from IConfiguration (binds to "Cloudflare" and "R2" sections)
> Dynamic clients manage their own `HttpClient` and resilience pipeline. Always dispose them when finished using a `using` statement or by calling `Dispose()`. Each dynamic client has isolated state (rate limiter, circuit breaker) and does not share resources with other clients.
219
+
175
220
## Error Handling
176
221
177
222
The SDK throws <xref:Cloudflare.NET.Core.Exceptions.CloudflareApiException> when the API returns an error:
Copy file name to clipboardExpand all lines: src/Cloudflare.NET/Cloudflare.NET.csproj
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@
5
5
6
6
<!-- NuGet Package Properties (common properties inherited from Directory.Build.props) -->
7
7
<PackageId>Cloudflare.NET.Api</PackageId>
8
-
<Version>3.3.0</Version>
8
+
<Version>3.4.0</Version>
9
9
<Description>Cloudflare.NET - A comprehensive C# client library for the Cloudflare REST API. Manage DNS records, Zones, R2 buckets, Workers, WAF rules, Turnstile, and security features with strongly-typed .NET code.</Description>
0 commit comments