PiBox.Plugins.Management.Unleash is a plugin
that allows to use feature flags
to enable CI/CD with control when and how are features enabled
.
To install the nuget package follow these steps:
dotnet add package PiBox.Plugins.Management.Unleash
or add as package reference to your .csproj
<PackageReference Include="PiBox.Plugins.Management.Unleash" Version="" />
This plugin uses
- https://github.com/microsoft/FeatureManagement-Dotnet (feature flags abstraction)
- https://github.com/Unleash/unleash-client-dotnet (client sdk)
- https://github.com/Unleash/unleash (server)
unleash:
appName: "my-fancy-app"
apiUri: "http://localhost:4242/api/"
apiToken: "[create-in-local-instance-web-ui]"
projectId: "default" //in free/opensource mode there is just one project, always the same
instanceTag: "my-fancy-backup2"
environment: "development"
public class ExampleService
{
private readonly IFeatureManager _featureManager;
public ExampleService(IFeatureManager featureManager)
{
_featureManager = featureManager;
}
public void CheckFeatureFlag()
{
var isEnabled= await featureManager.IsEnabledAsync("myFeatureFlag");
}
public void CheckFeatureFlagWithActivatedContextualUserIdFilter()
{
var isEnabled = await featureManager.IsEnabledAsync("hello", new UserIdContext(){UserId = "id1"});
}
}
[ApiController, Route("test")]
[FeatureGate("my-feature-flag-for-a-whole-controller")]
public class TestController : ControllerBase
{
[HttpGet]
[FeatureGate("my-feature-flag-for-get-action")]
public IActionResult Index()
{
return View();
}
[HttpPost]
[FeatureGate("my-feature-flag-for-post-action")]
public IActionResult Create()
{
return View();
}
}
@addTagHelper *, Microsoft.FeatureManagement.AspNetCore
<feature name="FeatureA">
<p>This can only be seen if 'FeatureA' is enabled.</p>
</feature>
using Microsoft.FeatureManagement.FeatureFilters;
IConfiguration Configuration { get; set;}
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc(options => {
options.Filters.AddForFeature<ThirdPartyActionFilter>(MyFeatureFlags.FeatureA);
});
}
app.UseMiddlewareForFeature<ThirdPartyMiddleware>(MyFeatureFlags.FeatureA);