Class Components
Provides factories for the standard implementations of LaunchDarkly component interfaces.
Inherited Members
Namespace: LaunchDarkly.Sdk.Server
Assembly: LaunchDarkly.ServerSdk.dll
Syntax
public static class Components
Remarks
Some of the configuration options in ConfigurationBuilder affect the entire SDK, but others are specific to one area of functionality, such as how the SDK receives feature flag updates or processes analytics events. For the latter, the standard way to specify a configuration is to call one of the static methods in Components (such as StreamingDataSource()), apply any desired configuration change to the object that that method returns (such as InitialReconnectDelay(TimeSpan)), and then use the corresponding method in ConfigurationBuilder (such as DataSource(IComponentConfigurer<IDataSource>)) to use that configured component in the SDK.
Properties
| Edit this page View SourceExternalUpdatesOnly
Returns a configuration object that disables direct connection with LaunchDarkly for feature flag updates.
Declaration
public static IComponentConfigurer<IDataSource> ExternalUpdatesOnly { get; }
Property Value
Type | Description |
---|---|
IComponentConfigurer<IDataSource> |
Remarks
Passing this to DataSource(IComponentConfigurer<IDataSource>) causes the SDK not to retrieve feature flag data from LaunchDarkly, regardless of any other configuration. This is normally done if you are using the Relay Proxy in "daemon mode", where an external process-- the Relay Proxy-- connects to LaunchDarkly and populates a persistent data store with the feature flag data. The data store could also be populated by another process that is running the LaunchDarkly SDK. If there is no external process updating the data store, then the SDK will not have any feature flag data and will return application default values only.
Examples
var config = Configuration.Builder(sdkKey)
.DataSource(Components.ExternalUpdatesOnly)
.DataStore(Components.PersistentDataStore(Redis.DataStore())) // assuming the Relay Proxy is using Redis
.Build();
|
Edit this page
View Source
InMemoryDataStore
Returns a factory for the default in-memory implementation of IDataStore.
Declaration
public static IComponentConfigurer<IDataStore> InMemoryDataStore { get; }
Property Value
Type | Description |
---|---|
IComponentConfigurer<IDataStore> |
Remarks
Since it is the default, you do not normally need to call this method, unless you need to create a data store instance for testing purposes.
NoEvents
Returns a configuration object that disables analytics events.
Declaration
public static IComponentConfigurer<IEventProcessor> NoEvents { get; }
Property Value
Type | Description |
---|---|
IComponentConfigurer<IEventProcessor> |
Remarks
Passing this to Events(IComponentConfigurer<IEventProcessor>) causes the SDK to discard all analytics events and not send them to LaunchDarkly, regardless of any other configuration.
Examples
var config = Configuration.Builder(sdkKey)
.Events(Components.NoEvents)
.Build();
|
Edit this page
View Source
NoLogging
A configuration object that disables logging.
Declaration
public static IComponentConfigurer<LoggingConfiguration> NoLogging { get; }
Property Value
Type | Description |
---|---|
IComponentConfigurer<LoggingConfiguration> |
Remarks
This is the same as Logging(LaunchDarkly.Logging.Logs.None)
.
Examples
var config = Configuration.Builder(sdkKey)
.Logging(Components.NoLogging)
.Build();
Methods
| Edit this page View SourceApplicationInfo()
Returns a configurable builder for the SDK's application metadata.
Declaration
public static ApplicationInfoBuilder ApplicationInfo()
Returns
Type | Description |
---|---|
ApplicationInfoBuilder | a configuration builder |
Remarks
Passing this to ApplicationInfo(ApplicationInfoBuilder) after setting any desired properties on the builder, applies this configuration to the SDK.
Examples
var config = Configuration.Builder(sdkKey)
.ApplicationInfo(
Components.ApplicationInfo().ApplicationID("MyApplication").ApplicationVersion("version123abc")
)
.Build();
|
Edit this page
View Source
BigSegments(IComponentConfigurer<IBigSegmentStore>)
Returns a configuration builder for the SDK's Big Segments feature.
Declaration
public static BigSegmentsConfigurationBuilder BigSegments(IComponentConfigurer<IBigSegmentStore> storeConfig)
Parameters
Type | Name | Description |
---|---|---|
IComponentConfigurer<IBigSegmentStore> | storeConfig | the factory/configuration builder for the underlying data store |
Returns
Type | Description |
---|---|
BigSegmentsConfigurationBuilder | a configuration builder |
Remarks
"Big Segments" are a specific type of segments. For more information, read the LaunchDarkly documentation about segments: https://docs.launchdarkly.com/home/users/segments
After configuring this object, use BigSegments(IComponentConfigurer<BigSegmentsConfiguration>) to store it in your SDK configuration. For example, using the Redis integration:
var config = Configuration.Builder(sdkKey)
.BigSegments(Components.BigSegments(Redis.DataStore().Prefix("app1"))
.ContextCacheSize(2000))
.Build();
You must always specify the storeConfig
parameter, to tell the SDK what database
you are using. Several database integrations exist for the LaunchDarkly SDK, each with its own
behavior and options specific to that database; this is described via some implementation of
IComponentConfigurer<IBigSegmentStore>
. The BigSegmentsConfigurationBuilder
adds configuration options for aspects of SDK behavior that are independent of the database. In the
example above,
Prefix
is an option specifically for the Redis integration, whereas
ContextCacheSize
is an option that can be used for any data store type.
Hooks()
Returns a configuration builder for the SDK's hook configuration.
var config = Configuration.Builder(sdkKey)
.Hooks(Components.Hooks()
.Add(new MyHook(...))
.Add(new MyOtherHook(...))
).Build();
Declaration
public static HookConfigurationBuilder Hooks()
Returns
Type | Description |
---|---|
HookConfigurationBuilder | a configuration builder |
Hooks(IEnumerable<Hook>)
Returns a configuration builder for the SDK's hook configuration, with an initial set of hooks given as a parameter.
Use this instead of Hooks() if you already have an existing collection of hooks satisfying the IEnumerable interface.
var listOfHooks = ...;
var config = Configuration.Builder(sdkKey)
.Hooks(Components.Hooks(listOfHooks)).Build();
Declaration
public static HookConfigurationBuilder Hooks(IEnumerable<Hook> hooks)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<Hook> | hooks | a collection of hooks |
Returns
Type | Description |
---|---|
HookConfigurationBuilder | a configuration builder |
HttpConfiguration()
Returns a configuration builder for the SDK's networking configuration.
Declaration
public static HttpConfigurationBuilder HttpConfiguration()
Returns
Type | Description |
---|---|
HttpConfigurationBuilder | a configuration builder |
Remarks
Passing this to Http(IComponentConfigurer<HttpConfiguration>), after setting any desired properties on the builder, applies this configuration to all HTTP/HTTPS requests made by the SDK.
Examples
var config = Configuration.Builder(sdkKey)
.Http(
Components.HttpConfiguration()
.ConnectTimeout(TimeSpan.FromMilliseconds(3000))
)
.Build();
|
Edit this page
View Source
Logging()
Returns a configuration builder for the SDK's logging configuration.
Declaration
public static LoggingConfigurationBuilder Logging()
Returns
Type | Description |
---|---|
LoggingConfigurationBuilder | a configuration builder |
Remarks
Passing this to Logging(IComponentConfigurer<LoggingConfiguration>), after setting any desired properties on the builder, applies this configuration to the SDK.
The default behavior, if you do not change any properties, is to send log output to
Error, with a minimum level of Info
(that is, Debug
logging
is disabled).
For more about how logging works in the SDK, see the SDK SDK reference guide.
Examples
var config = Configuration.Builder("my-sdk-key")
.Logging(Components.Logging().Level(LogLevel.Warn)))
.Build();
See Also
| Edit this page View SourceLogging(ILogAdapter)
Returns a configuration builder for the SDK's logging configuration, specifying the logging implementation.
Declaration
public static LoggingConfigurationBuilder Logging(ILogAdapter adapter)
Parameters
Type | Name | Description |
---|---|---|
ILogAdapter | adapter | an |
Returns
Type | Description |
---|---|
LoggingConfigurationBuilder | a configuration builder |
Remarks
This is a shortcut for calling Logging() and then
Adapter(ILogAdapter), to specify a logging implementation
other than the default one. For instance, in a .NET Core application you can use
LaunchDarkly.Logging.Logs.CoreLogging
to use the standard .NET Core logging framework.
If you do not also specify a minimum logging level with Level(LogLevel),
or with some other filtering mechanism that is defined by an external logging framework, then the
log output will show all logging levels including Debug
.
For more about log adapters, see Adapter(ILogAdapter).
For more about how logging works in the SDK, see the SDK SDK reference guide.
Examples
var config = Configuration.Builder(sdkKey)
.Logging(Components.Logging(Logs.CoreLogging(coreLoggingFactory)))
.Build();
See Also
| Edit this page View SourcePersistentDataStore(IComponentConfigurer<IPersistentDataStoreAsync>)
Returns a configurable factory for a persistent data store.
Declaration
public static PersistentDataStoreBuilder PersistentDataStore(IComponentConfigurer<IPersistentDataStoreAsync> storeConfig)
Parameters
Type | Name | Description |
---|---|---|
IComponentConfigurer<IPersistentDataStoreAsync> | storeConfig | the configuration builder/factory for the underlying data store |
Returns
Type | Description |
---|---|
PersistentDataStoreBuilder | a configuration builder |
Remarks
This method takes a configuration builder that is provided by some persistent data store implementation (i.e. a database integration), and converts it to a PersistentDataStoreBuilder which can be used to add caching behavior. You can then pass the PersistentDataStoreBuilder object to DataStore(IComponentConfigurer<IDataStore>) to use this configuration in the SDK. Example usage:
var myStore = Components.PersistentDataStore(Redis.FeatureStore())
.CacheTtl(TimeSpan.FromSeconds(45));
var config = Configuration.Builder(sdkKey)
.DataStore(myStore)
.Build();
The method is overloaded because some persistent data store implementations use IPersistentDataStore while others use IPersistentDataStoreAsync.
PersistentDataStore(IComponentConfigurer<IPersistentDataStore>)
Returns a configurable factory for a persistent data store.
Declaration
public static PersistentDataStoreBuilder PersistentDataStore(IComponentConfigurer<IPersistentDataStore> storeConfig)
Parameters
Type | Name | Description |
---|---|---|
IComponentConfigurer<IPersistentDataStore> | storeConfig | the configuration builder/factory for the underlying data store |
Returns
Type | Description |
---|---|
PersistentDataStoreBuilder | a configuration builder |
Remarks
This method takes a configuration builder that is provided by some persistent data store implementation (i.e. a database integration), and converts it to a PersistentDataStoreBuilder which can be used to add caching behavior. You can then pass the PersistentDataStoreBuilder object to DataStore(IComponentConfigurer<IDataStore>) to use this configuration in the SDK. Example usage:
var myStore = Components.PersistentDataStore(Redis.FeatureStore())
.CacheTtl(TimeSpan.FromSeconds(45));
var config = Configuration.Builder(sdkKey)
.DataStore(myStore)
.Build();
The method is overloaded because some persistent data store implementations use IPersistentDataStore while others use IPersistentDataStoreAsync.
PollingDataSource()
Returns a configurable factory for using polling mode to get feature flag data.
Declaration
public static PollingDataSourceBuilder PollingDataSource()
Returns
Type | Description |
---|---|
PollingDataSourceBuilder | a builder for setting polling connection properties |
Remarks
This is not the default behavior; by default, the SDK uses a streaming connection to receive feature flag data from LaunchDarkly. In polling mode, the SDK instead makes a new HTTP request to LaunchDarkly at regular intervals. HTTP caching allows it to avoid redundantly downloading data if there have been no changes, but polling is still less efficient than streaming and should only be used on the advice of LaunchDarkly support.
To use polling mode, call this method to obtain a builder, change its properties with the PollingDataSourceBuilder methods, and pass it to DataSource(IComponentConfigurer<IDataSource>).
Setting Offline(bool) to true will superseded this setting and completely disable network requests.
Examples
var config = Configuration.Builder(sdkKey)
.DataSource(Components.PollingDataSource()
.PollInterval(TimeSpan.FromSeconds(45)))
.Build();
|
Edit this page
View Source
SendEvents()
Returns a configuration builder for analytics event delivery.
Declaration
public static EventProcessorBuilder SendEvents()
Returns
Type | Description |
---|---|
EventProcessorBuilder | a builder for setting event properties |
Remarks
The default configuration has events enabled with default settings. If you want to customize this behavior, call this method to obtain a builder, change its properties with the EventProcessorBuilder methods, and pass it to Events(IComponentConfigurer<IEventProcessor>).
To completely disable sending analytics events, use NoEvents instead.
Examples
var config = Configuration.Builder(sdkKey)
.Events(Components.SendEvents()
.Capacity(5000)
.FlushInterval(TimeSpan.FromSeconds(2)))
.Build();
|
Edit this page
View Source
ServiceEndpoints()
Returns a builder for configuring custom service URIs.
Declaration
public static ServiceEndpointsBuilder ServiceEndpoints()
Returns
Type | Description |
---|---|
ServiceEndpointsBuilder | a configuration builder |
Remarks
Passing this to ServiceEndpoints(ServiceEndpointsBuilder), after setting any desired properties on the builder, applies this configuration to the SDK.
Most applications will never need to use this method. The main use case is when connecting to a LaunchDarkly Relay Proxy instance. For more information, see ServiceEndpointsBuilder.
Examples
var config = Configuration.Builder(sdkKey)
.ServiceEndpoints(Components.ServiceEndpoints().RelayProxy("http://my-relay-hostname:80"))
.Build();
See Also
| Edit this page View SourceStreamingDataSource()
Returns a configurable factory for using streaming mode to get feature flag data.
Declaration
public static StreamingDataSourceBuilder StreamingDataSource()
Returns
Type | Description |
---|---|
StreamingDataSourceBuilder | a builder for setting streaming connection properties |
Remarks
By default, the SDK uses a streaming connection to receive feature flag data from LaunchDarkly. To use the default behavior, you do not need to call this method. However, if you want to customize the behavior of the connection, call this method to obtain a builder, change its properties with the StreamingDataSourceBuilder methods, and pass it to DataSource(IComponentConfigurer<IDataSource>).
Setting Offline(bool) to true will superseded this setting and completely disable network requests.
Examples
var config = Configuration.Builder(sdkKey)
.DataSource(Components.StreamingDataSource()
.InitialReconnectDelay(TimeSpan.FromMilliseconds(500)))
.Build();
|
Edit this page
View Source
WrapperInfo()
Returns a configuration builder for setting wrapper information. Applications do not need to call this method.
Declaration
public static WrapperInfoBuilder WrapperInfo()
Returns
Type | Description |
---|---|
WrapperInfoBuilder | a configuration builder |
Remarks
This is intended for use by LaunchDarkly in the development of wrapper SDKs.