Skip to content

Instantly share code, notes, and snippets.

@xtrmstep
Last active November 15, 2020 15:11
Show Gist options
  • Save xtrmstep/15b19d9fcde4d51dd9dc84e63af03e69 to your computer and use it in GitHub Desktop.
Save xtrmstep/15b19d9fcde4d51dd9dc84e63af03e69 to your computer and use it in GitHub Desktop.
Using Feature Flags and Externalized configuration .NET Core app with Flagsmith - 2
public class BulletTrainRemoteConfiguration : IRemoteConfiguration
{
private readonly string _userIdentity;
private static readonly object LockObject = new object();
public BulletTrainRemoteConfiguration(RemoteConfigurationSettings settings)
{
if (BulletTrainClient.instance == null)
lock (LockObject)
if (BulletTrainClient.instance == null)
{
var configuration = new BulletTrainConfiguration
{
ApiUrl = settings.ApiUrl,
EnvironmentKey = settings.EnvironmentKey
};
var bulletClient = new BulletTrainClient(configuration);
}
_userIdentity = settings.ClientAppId;
}
public async Task<List<Feature>> GetFeatures()
{
var flags = await BulletTrainClient.instance.GetFeatureFlags(_userIdentity);
var features = flags.Select(f => new Feature
{
Name = f.GetFeature().GetName(),
Value = f.IsEnabled()
}).ToList();
return features;
}
public Task<bool> IsFeatureEnabled(string key)
{
return BulletTrainClient.instance.HasFeatureFlag(key, _userIdentity);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment