Show / Hide Table of Contents

Class ConfigurationBuilder

A mutable object that uses the Builder pattern to specify properties for a Configuration object.

Inheritance
System.Object
ConfigurationBuilder
Namespace: LaunchDarkly.Sdk.Client
Assembly: LaunchDarkly.ClientSdk.dll
Syntax
public sealed class ConfigurationBuilder : Object
Remarks

Obtain an instance of this class by calling Builder(String).

All of the builder methods for setting a configuration property return a reference to the same builder, so they can be chained together.

Examples
    var config = Configuration.Builder("my-mobile-key").AllAttributesPrivate(true).EventCapacity(1000).Build();

Methods

Build()

Creates a Configuration based on the properties that have been set on the builder. Modifying the builder after this point does not affect the returned Configuration.

Declaration
public Configuration Build()
Returns
Type Description
Configuration

the configured Configuration object

DataSource(IComponentConfigurer<IDataSource>)

Sets the implementation of the component that receives feature flag data from LaunchDarkly, using a factory object.

Declaration
public ConfigurationBuilder DataSource(IComponentConfigurer<IDataSource> dataSourceConfig)
Parameters
Type Name Description
IComponentConfigurer<IDataSource> dataSourceConfig

the factory object

Returns
Type Description
ConfigurationBuilder

the same builder

Remarks

Depending on the implementation, the factory may be a builder that allows you to set other configuration options as well.

The default is StreamingDataSource(). You may instead use PollingDataSource(). See those methods for details on how to configure them.

This overwrites any previous options set with DataSource(IComponentConfigurer<IDataSource>). If you want to set multiple options, set them on the same StreamingDataSourceBuilder or PollingDataSourceBuilder.

DiagnosticOptOut(Boolean)

Specifies whether true to opt out of sending diagnostic events.

Declaration
public ConfigurationBuilder DiagnosticOptOut(bool diagnosticOptOut)
Parameters
Type Name Description
System.Boolean diagnosticOptOut

true to disable diagnostic events

Returns
Type Description
ConfigurationBuilder

the same builder

Remarks

Unless this is set to true, the client will send some diagnostics data to the LaunchDarkly servers in order to assist in the development of future SDK improvements. These diagnostics consist of an initial payload containing some details of SDK in use, the SDK's configuration, and the platform the SDK is being run on, as well as payloads sent periodically with information on irregular occurrences such as dropped events.

EnableBackgroundUpdating(Boolean)

Sets whether to enable feature flag polling when the application is in the background.

Declaration
public ConfigurationBuilder EnableBackgroundUpdating(bool enableBackgroundUpdating)
Parameters
Type Name Description
System.Boolean enableBackgroundUpdating

true if background updating should be allowed

Returns
Type Description
ConfigurationBuilder

the same builder

Remarks

By default, on Android and iOS the SDK can still receive feature flag updates when an application is in the background, but it will use polling rather than maintaining a streaming connection (and will use the background polling interval rather than the regular polling interval). If you set this property to false, it will not check for feature flag updates until the application returns to the foreground.

See Also
BackgroundPollInterval(TimeSpan)
BackgroundPollInterval(TimeSpan)

EvaluationReasons(Boolean)

Set to true if LaunchDarkly should provide additional information about how flag values were calculated.

Declaration
public ConfigurationBuilder EvaluationReasons(bool evaluationReasons)
Parameters
Type Name Description
System.Boolean evaluationReasons

true if evaluation reasons are desired

Returns
Type Description
ConfigurationBuilder

the same builder

Remarks

The additional information will then be available through the client's "detail" methods such as BoolVariationDetail(String, Boolean). Since this increases the size of network requests, such information is not sent unless you set this option to true.

Events(IComponentConfigurer<IEventProcessor>)

Sets the implementation of the component that processes analytics events.

Declaration
public ConfigurationBuilder Events(IComponentConfigurer<IEventProcessor> eventsConfig)
Parameters
Type Name Description
IComponentConfigurer<IEventProcessor> eventsConfig

a builder/factory object for event configuration

Returns
Type Description
ConfigurationBuilder

the same builder

Remarks

The default is SendEvents(), but you may choose to set it to a customized EventProcessorBuilder, a custom implementation (for instance, a test fixture), or disable events with NoEvents.

This overwrites any previous options set with Events(IComponentConfigurer<IEventProcessor>). If you want to set multiple options, set them on the same EventProcessorBuilder.

GenerateAnonymousKeys(Boolean)

Set to true to make the SDK provide unique keys for anonymous contexts.

Declaration
public ConfigurationBuilder GenerateAnonymousKeys(bool generateAnonymousKeys)
Parameters
Type Name Description
System.Boolean generateAnonymousKeys

true to enable automatic anonymous key generation

Returns
Type Description
ConfigurationBuilder

the same builder

Remarks

If enabled, this option changes the SDK's behavior whenever the Context (as given to methods like Init(String, Context, TimeSpan) or Identify(Context, TimeSpan)) has an Anonymous property of true, as follows:

  • The first time this happens in the application, the SDK will generate a pseudo-random GUID and overwrite the context's Key with this string.
  • The SDK will then cache this key so that the same key will be reused next time.
  • This uses the same mechanism as the caching of flag values, so if persistent storage is available (see Persistence()), the key will persist across restarts; otherwise, it will persist only during the lifetime of the LdClient.

If you use multiple ContextKinds, this behavior is per-kind: that is, a separate randomized key is generated and cached for each context kind.

A Context must always have a key, even if the key will later be overwritten by the SDK, so if you use this functionality you must still provide a placeholder key. This ensures that if the SDK configuration is changed so GenerateAnonymousKeys(Boolean) is no longer enabled, the SDK will still be able to use the context for evaluations.

Http(HttpConfigurationBuilder)

Sets the SDK's networking configuration, using a configuration builder obtained from HttpConfiguration(). The builder has methods for setting individual HTTP-related properties.

Declaration
public ConfigurationBuilder Http(HttpConfigurationBuilder httpConfigurationBuilder)
Parameters
Type Name Description
HttpConfigurationBuilder httpConfigurationBuilder

a builder for HTTP configuration

Returns
Type Description
ConfigurationBuilder

the top-level builder

Remarks

This overwrites any previous options set with Http(HttpConfigurationBuilder). If you want to set multiple options, set them on the same HttpConfigurationBuilder.

Logging(ILogAdapter)

Sets the SDK's logging destination.

Declaration
public ConfigurationBuilder Logging(ILogAdapter logAdapter)
Parameters
Type Name Description
LaunchDarkly.Logging.ILogAdapter logAdapter

an ILogAdapter for the desired logging implementation

Returns
Type Description
ConfigurationBuilder

the same builder

Remarks

This is a shortcut for Logging(Components.Logging(logAdapter)). You can use it when you only want to specify the basic logging destination, and do not need to set other log properties.

For more about how logging works in the SDK, see the LaunchDarkly feature guide.

Examples

var config = Configuration.Builder("my-sdk-key") .Logging(Logs.ToWriter(Console.Out)) .Build();

Logging(LoggingConfigurationBuilder)

Sets the SDK's logging configuration, using a configuration builder obtained from Logging().

Declaration
public ConfigurationBuilder Logging(LoggingConfigurationBuilder loggingConfigurationBuilder)
Parameters
Type Name Description
LoggingConfigurationBuilder loggingConfigurationBuilder

a builder for logging configuration

Returns
Type Description
ConfigurationBuilder

the top-level builder

Remarks

As a shortcut for disabling logging, you may use NoLogging instead. If all you want to do is to set the basic logging destination, and you do not need to set other logging properties, you can use Logging(ILogAdapter) instead.

For more about how logging works in the SDK, see the LaunchDarkly feature guide.

This overwrites any previous options set with Logging(LoggingConfigurationBuilder). If you want to set multiple options, set them on the same LoggingConfigurationBuilder.

Examples

var config = Configuration.Builder("my-sdk-key") .Logging(Components.Logging().Level(LogLevel.Warn))) .Build();

See Also
Logging()
Logging(ILogAdapter)
NoLogging
Logging(ILogAdapter)

MobileKey(String)

Sets the key for your LaunchDarkly environment.

Declaration
public ConfigurationBuilder MobileKey(string mobileKey)
Parameters
Type Name Description
System.String mobileKey

the mobile key

Returns
Type Description
ConfigurationBuilder

the same builder

Remarks

This should be the "mobile key" field for the environment on your LaunchDarkly dashboard.

Offline(Boolean)

Sets whether or not this client is offline. If true, no calls to LaunchDarkly will be made.

Declaration
public ConfigurationBuilder Offline(bool offline)
Parameters
Type Name Description
System.Boolean offline

true if the client should remain offline

Returns
Type Description
ConfigurationBuilder

the same builder

Persistence(PersistenceConfigurationBuilder)

Sets the SDK's persistent storage configuration, using a configuration builder obtained from Persistence().

Declaration
public ConfigurationBuilder Persistence(PersistenceConfigurationBuilder persistenceConfigurationBuilder)
Parameters
Type Name Description
PersistenceConfigurationBuilder persistenceConfigurationBuilder

a builder for persistence configuration

Returns
Type Description
ConfigurationBuilder

the top-level builder

Remarks

The persistent storage mechanism allows the SDK to immediately access the last known flag data for the user, if any, if it is offline or has not yet received data from LaunchDarkly.

By default, the SDK uses a persistence mechanism that is specific to each platform: on Android and iOS it is the native preferences store, and in the .NET Standard implementation for desktop apps it is the System.IO.IsolatedStorage API. You may use the builder methods to substitute a custom implementation or change related parameters.

This overwrites any previous options set with this method. If you want to set multiple options, set them on the same PersistenceConfigurationBuilder.

Examples

var config = Configuration.Builder("my-sdk-key") .Persistence(Components.Persistence().MaxCachedUsers(10)) .Build();

See Also
Persistence()
NoPersistence
PersistenceConfigurationBuilder

ServiceEndpoints(ServiceEndpointsBuilder)

Sets the SDK's service URIs, using a configuration builder obtained from ServiceEndpoints().

Declaration
public ConfigurationBuilder ServiceEndpoints(ServiceEndpointsBuilder serviceEndpointsBuilder)
Parameters
Type Name Description
ServiceEndpointsBuilder serviceEndpointsBuilder

the subconfiguration builder object

Returns
Type Description
ConfigurationBuilder

the main configuration builder

Remarks

This overwrites any previous options set with ServiceEndpoints(ServiceEndpointsBuilder). If you want to set multiple options, set them on the same ServiceEndpointsBuilder.

See Also
ServiceEndpoints()
ServiceEndpointsBuilder
In This Article
Back to top Generated by DocFX