IFeatureManagerSnapshot

The IFeatureManagerSnapshot service can be injected anywhere else more suitable helper methods aren't available.

private readonly IFeatureManagerSnapshot _featureManager;

public UsersController(IFeatureManagerSnapshot featureManager)
{
    _featureManager = featureManager;
}

[Route("")]
public async Task<IActionResult> Index()
{
    var feature1Enabled = await _featureManager.IsEnabledAsync(FeatureFlags.Feature1);

    return View(feature1Enabled ? "Feature1Index" : "Index");
}

IFeatureManagerSnapshot persists the values of the flags returned throughout the current request, and is recommended to be used over calling IFeatureManager directly, so you don't end up with different values for the a flag on the same request.

IFeatureManager is used by the FeatureMangerSnapshot to retrieve the computed value of each flag on each call, and it can be used the same way IFeatureManagerSnapshot is used.

Last updated