For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
Sign inTry it free
DocsGuidesSDKsIntegrationsAPI docsTutorialsFlagship blog
DocsGuidesSDKsIntegrationsAPI docsTutorialsFlagship blog
  • SDKs
    • SDK concepts
    • SDK features
    • Client-side SDKs
    • Server-side SDKs
    • AI SDKs
    • Edge SDKs
    • OpenFeature providers
      • .NET (server-side) provider
      • Java provider
      • Node.js (server-side) provider
      • PHP provider
    • Observability SDKs
    • Relay Proxy
Sign inTry it free
LogoLogo
On this page
  • Get started
  • Version compatibility
  • Install the provider
  • Initialize the provider
  • Construct a context
  • Evaluate a context
  • Access the LaunchDarkly client
SDKsOpenFeature providers

OpenFeature provider for .NET (server-side) SDK

Was this page helpful?
Previous

OpenFeature provider for Java SDK

Next
Built with

This topic documents how to get started with the LaunchDarkly OpenFeature provider for the .NET (server-side) SDK.

Provider quick links

LaunchDarkly’s OpenFeature providers are open source. In addition to this reference guide, we provide source, API reference documentation, and a sample application:

ResourceLocation
OpenFeature Provider API documentationProvider API docs
GitHub repositoryopenfeature-dotnet-server
Sample applicationSample OpenFeature .NET provider application
Published moduleNuGet

Get started

The LaunchDarkly OpenFeature provider for the .NET (server-side) SDK is intended for use in multi-user systems such as web servers and application. It is not intended for use in desktop and embedded systems applications.

Follow these instructions to start using the LaunchDarkly OpenFeature provider for the .NET (server-side) SDK in your application.

Version compatibility

The LaunchDarkly OpenFeature provider for the .NET (server-side) SDK is compatible with the OpenFeature .NET SDK v2.0.

The provider is compatible with .NET 6.0+, .NET Framework 4.7.1+, and .NET Standard 2.0+.

Install the provider

First, add the LaunchDarkly and OpenFeature packages:

Shell
$dotnet add package LaunchDarkly.ServerSdk
$dotnet add package LaunchDarkly.OpenFeature.ServerProvider
$dotnet add package OpenFeature

Next, import the OpenFeature and LaunchDarkly namespaces in your application code:

LaunchDarkly .NET (server-side) provider
1using LaunchDarkly.OpenFeature.ServerProvider;
2using LaunchDarkly.Sdk.Server;

Initialize the provider

After you install and import the provider, create a single, shared instance of Provider. Specify your SDK key here to authorize your application to connect to a particular environment within LaunchDarkly.

Here’s how:

C#
1var config = Configuration.Builder("YOUR_SDK_KEY")
2 .StartWaitTime(TimeSpan.FromSeconds(10))
3 .Build();
4
5var provider = new Provider(config);
6
7await OpenFeature.Api.Instance.SetProviderAsync(provider);
8
9var client = OpenFeature.Api.Instance.GetClient();

The configuration options are from the LaunchDarkly .NET (server-side) SDK. To learn more about the configuration options available, read Configuration.

The .NET provider uses an SDK key

The LaunchDarkly .NET (server-side) provider uses an SDK key. Keys are specific to each project and environment. They are available on the SDK keys page under Settings. To learn more about key types, read Keys.

Construct a context

A context is a generalized way of referring to the people, services, machines, or other resources that encounter feature flags in your product. The OpenFeature specification calls these evaluation contexts.

In the LaunchDarkly provider, contexts:

  • always have a particular context kind. If you do not specify a kind, the provider treats the context as having a “user” kind. To specify a different kind, including a multi-context, you must include a kind attribute.
  • must have a targeting key. This is optional in the OpenFeature specification, but LaunchDarkly requires a key for evaluation. You can specify this using targetingKey, as in the OpenFeature specification, or key, which is the typical LaunchDarkly identifier for the targeting key.

Here are examples of a context:

1var context = EvaluationContext.Builder()
2 .Set("targetingKey", "example-user-key") // Could also use "key" instead of "targetingKey".
3 .Build();

For additional examples, read OpenFeature specific considerations in the provider GitHub repository.

Evaluate a context

To evaluate feature flags for a context, use the OpenFeature Evaluation API. For example:

Evaluate a context
1var flagValue = await client.GetBooleanValueAsync("example-flag-key", false, context);

Access the LaunchDarkly client

You may need access to the LdClient from within the LaunchDarkly .NET (server-side) SDK if you are working on use cases not supported by OpenFeature, such as migration flags or sending custom events.

To access the LdClient, use GetClient():

C#
1var ldClient = provider.GetClient()