https://www.nuget.org/packages/mhlabs.feature-toggle.client/
Extension methods look like this:
public static class ServiceCollectionExtensions
{
/// Registers client with RetryLevel.Read and UseCircuitBreaker = true
public static IServiceCollection AddFeatureToggleClient(this IServiceCollection services, string baseUrl)
{
return services.AddFeatureToggleClient(new HttpOptions
{
BaseUrl = baseUrl,
RetryLevel = RetryLevel.Read,
UseCircuitBreaker = true
});
}
public static IServiceCollection AddFeatureToggleClient(this IServiceCollection services, HttpOptions options)
{
services.AddSingleton<IFeatureToggleClient, FeatureToggleClient>();
services.AddSingleton<IFeatureToggleConfiguration, FeatureToggleConfiguration>();
services.AddSignedHttpClient<IFeatureToggleService, FeatureToggleService>(options);
return services;
}
}
serviceCollection.AddFeatureToggleClient("https://api.feature-service.com");
var options = new HttpOptions ()
{
BaseUrl = "https://api.feature-service.com",
RetryLevel = RetryLevel.Read,
UseCircuitBreaker = true
}
serviceCollection.AddFeatureToggleClient(options);
public class MyService
{
private readonly IFeatureToggleClient _client;
private readonly IMyOldService _oldService;
private readonly IMyNewService _newService;
public MyService (IFeatureToggleClient client, IMyOldService oldService, IMyNewService newService)
{
_client = client;
_oldService = oldService;
_newService = newService;
}
public async Task<ServiceResponse> GetForMember(string userKey)
{
var flag = await _client.Get("ai-service.v2", userKey, false);
return flag.Enabled ?
await _newService.Get() :
await _oldService.Get();
}
}
public interface IFeatureToggleResponse
{
bool Active { get; set; }
string Error { get; set; }
long TimeStamp { get; }
}