Skip to content

How to handle FeatureFlags? #1012

Closed Answered by caiogarcia
caiogarcia asked this question in Q&A
Discussion options

You must be logged in to vote

I figure it out by my self, but if you have the same case you can use the following code.

services.AddMediatR(cfg =>
{
    cfg.TypeEvaluator = (type) =>
    {
        var attribute = type.GetCustomAttribute<FeatureGateAttribute>();
        return attribute == null ||
               attribute.Features.All(feature => configuration.GetValue<bool>(feature));
    };
    cfg.RegisterServicesFromAssemblyContaining(typeof(IServiceCollectionExtensions));
});

And mark your handlers with FeatureGate attribute from Microsoft.FeatureManagement.AspNetCore package.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by caiogarcia
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant