Last active
November 15, 2020 15:11
-
-
Save xtrmstep/15b19d9fcde4d51dd9dc84e63af03e69 to your computer and use it in GitHub Desktop.
Using Feature Flags and Externalized configuration .NET Core app with Flagsmith - 2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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