Fauna v10 .NET/C# Driver 1.0.1
 
Loading...
Searching...
No Matches
Configuration.cs
Go to the documentation of this file.
1using System.Threading;
2using Fauna.Core;
3using Fauna.Util;
4using Microsoft.Extensions.Logging;
5
6namespace Fauna;
7
12public record class Configuration
13{
17 public bool DisposeHttpClient { get; } = true;
18
23 public TimeSpan ClientBufferTimeout { get; init; } = TimeSpan.FromSeconds(5);
24
28 public HttpClient HttpClient { get; init; }
29
33 public string Secret { get; init; } = Environment.GetEnvironmentVariable("FAUNA_SECRET") ?? string.Empty;
34
38 public Uri Endpoint { get; init; } = Endpoints.GetFaunaEndpoint();
39
43 public QueryOptions DefaultQueryOptions { get; init; } = new();
44
48 public RetryConfiguration RetryConfiguration { get; init; } = new(3, TimeSpan.FromSeconds(20));
49
50
54 public IStatsCollector? StatsCollector { get; init; } = new StatsCollector();
55
62 public Configuration(string secret = "", HttpClient? httpClient = null, ILogger? logger = null)
63 {
64 if (!string.IsNullOrEmpty(secret))
65 {
66 Secret = secret;
67 }
68
69 if (httpClient != null)
70 {
71 HttpClient = httpClient;
72 DisposeHttpClient = false;
73 }
74 else
75 {
76 HttpClient = new HttpClient { Timeout = Timeout.InfiniteTimeSpan };
77 }
78
79 if (logger != null)
80 {
81 Logger.Initialize(logger);
82 }
83 }
84
85 internal void Validate()
86 {
87 if (string.IsNullOrEmpty(Secret))
88 throw new ArgumentNullException(
89 nameof(Secret),
90 "Need to set FAUNA_SECRET environment variable or pass a secret as a parameter when creating the Client."
91 );
92 }
93}
Configuration is a class used to configure a Fauna Client. It encapsulates various settings such as t...
HttpClient HttpClient
The HTTP Client to use for requests.
Uri Endpoint
The endpoint URL of the Fauna server.
string Secret
The secret key used for authentication.
bool DisposeHttpClient
Whether the Client should dispose of the HttpClient on Dispose.
Configuration(string secret="", HttpClient? httpClient=null, ILogger? logger=null)
Initializes a new instance of the Configuration record with the specified secret key.
TimeSpan ClientBufferTimeout
Additional buffer to add to QueryOptions.QueryTimeout when setting the HTTP request timeout on the Ht...
IStatsCollector? StatsCollector
StatsCollector for the client.
QueryOptions DefaultQueryOptions
Default options for queries sent to Fauna.
Represents the options for customizing Fauna queries.
A class representing a retry configuration for queries.
The default implementation of IStatsCollector.
An interface used by a client instance for aggregating stats across all queries.