I am learning Azure App Configuration - Feature manager.
I am trying to understand if a custom feature filter that we write needs to use some parameters which are not part of HttpContext.
How can we pass extra parameters when we call IFeatureManager.IsEnabled("featurename") which triggers Evaulate method of custom filter.
But how an azure function app or webjob will use it.
[FilterAlias("AllowedUsers")]
public class AllowedUsersFeatureFilter : IFeatureFilter
{
private readonly IHttpContextAccessor _httpContextAccessor;
public AllowedUsersFeatureFilter(IHttpContextAccessor httpContextAccessor)
{
_httpContextAccessor = httpContextAccessor;
}
// HOW CAN WE PASS SOME parameter when we call IFeatureManager.IsEnabled("featurename")
public bool Evaluate**(FeatureFilterEvaluationContext context)**
{
var featureFilterParams = context.Parameters.Get<AllowedUsersFilterSettings>();
if (featureFilterParams == null)
return false;
var userEmail = _httpContextAccessor.HttpContext.User?.FindFirst(ClaimTypes.Upn)?.Value;
var alias= userEmail?.Split('@').First();
return featureFilterParams.Aliases.Split(',').Contains(alias, StringComparer.OrdinalIgnoreCase);
}
}
There is an issue open for this on the FeatureManagement repository. https://github.com/microsoft/FeatureManagement-Dotnet/issues/2. With the initial preview this is not possible. It should be in by next release.
Currently using AsyncLocal to flow an execution context would be a possible solution, however it is a work-around until the actual capability to pass in the context is available.