Interface IAnalyticsApiFactory
- Namespace
- Cloudflare.NET.Analytics
- Assembly
- Cloudflare.NET.Analytics.dll
Defines the contract for a factory that creates named IAnalyticsApi instances. This allows applications to query analytics data from multiple Cloudflare accounts simultaneously.
public interface IAnalyticsApiFactory
Remarks
Named clients are registered using the AddCloudflareAnalytics(IServiceCollection, string) overload with a name parameter. The corresponding Cloudflare API options (with API token and GraphQL URL) must also be registered with the same name.
// Registration - first register the Cloudflare API options with the name
services.AddCloudflareApiClient("account1", options => {
options.ApiToken = "token1";
options.GraphQlApiUrl = "https://api.cloudflare.com/client/v4/graphql";
});
services.AddCloudflareAnalytics("account1");
services.AddCloudflareApiClient("account2", options => {
options.ApiToken = "token2";
});
services.AddCloudflareAnalytics("account2");
// Usage via factory
public class MyService(IAnalyticsApiFactory factory)
{
public async Task DoSomething()
{
var account1Api = factory.CreateClient("account1");
var account2Api = factory.CreateClient("account2");
// ...
}
}
Methods
CreateClient(string)
Creates an IAnalyticsApi instance configured with the specified named options.
IAnalyticsApi CreateClient(string name)
Parameters
namestringThe name of the client configuration to use. This must match the name used during registration.
Returns
- IAnalyticsApi
A new IAnalyticsApi instance configured with the named options.
Exceptions
- InvalidOperationException
Thrown when no client with the specified name has been registered.