“LaunchDarkly provides simple, scalable feature flag & toggle management (feature management) for the modern enterprise.”
You can create a trial account at launchdarkly.com and their docs are at docs.launchdarkly.com are really good.
All the code snippets below are available at https://github.com/carlpaton/LaunchDarklyDemo
Launch Darkly packages
The API’s for the Launch Darkly client are avalible in these SDKs
Launch Darkly Projects & Environments
Each Launch Darkly project can have multiple environments, the default project is called Default Project
but you can add more.
Each environment has its own SDK key
, when creating the client this is a required parameter. The default environments are Test
and Production
. Its sensible for your code to have no knowledge of the environments and simply rely on the correct SDK key
to be injected.
Example client:
1 | var launchDarklyClient = new LdClient(_sdkKey); |
Segments
Segments can be applied to a flag.
Local development
When developing locally the LdClient
can be configured to return pre-defined settings. This would also be useful when running integration tests.
1 | if (_environment.IsDevelopment() |
SDK
BoolVariation
The examples below assume _sdkKey
is injected and the features sweet-feature-name-1
and sweet-feature-name-2
has been configured in Launch Darkly.
User.WithKey
This works with both LaunchDarkly.Client
or LaunchDarkly.ServerSdk
.
This example will return true only when the userId
of cc04e5b8-b483-47fe-8ce6-0098487e91a8
is configured in Launch Darkly under the flag sweet-feature-name-1
.
1 | var defaultValue = false; |
User.Builder
This only works with LaunchDarkly.ServerSdk
.
This example will return true when either of the following is configured in Launch Darkly under the flag sweet-feature-name-2
. These are custom fields in Launch Darkly.
cityId
ofea2b6efc-020d-4469-a993-1bd5baf78adc
ORregionId
ofnz
1 | var defaultValue = false; |