-
Notifications
You must be signed in to change notification settings - Fork 111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot use the TargetingFilter in .NET class library project #446
Comments
Hi, @bdscarboro1 Start from Microsoft.FeatureManagement v3.1.0, We just released v3.3.0, where we made parameters of the constructors of the built-in feature filters mentioned above optional. This change is mainly for improving the experience of non-DI usage of feature management library. So, I would suggest you update to the latest Microsoft.FeatureManagement v3.3.0. There are two targeting filters in this lib, They are respectively designed for console app(explicit For more details, please read Targeting. Here is an example of how to use feature management without dependency injection. using Microsoft.Extensions.Configuration;
using Microsoft.FeatureManagement;
using Microsoft.FeatureManagement.FeatureFilters;
IConfiguration configuration = new ConfigurationBuilder()
.AddJsonFile("appsettings.json")
.Build();
IFeatureDefinitionProvider featureDefinitionProvider = new ConfigurationFeatureDefinitionProvider(configuration);
IFeatureManager featureManager = new FeatureManager(featureDefinitionProvider)
{
FeatureFilters = new List<IFeatureFilterMetadata> { new ContextualTargetingFilter() }
};
var targetingContext = new TargetingContext()
{
UserId = "Jeff"
};
bool res = await featureManager.IsEnabledAsync("MyFeature", targetingContext); The feature flag in Microsoft.FeatureManagement schema: {
"feature_management": {
"feature_flags": [
{
"id": "MyFeature",
"enabled": true,
"conditions": {
"client_filters": [
{
"name": "Microsoft.Targeting",
"parameters": {
"Audience": {
"Users": [ "Jeff" ]
}
}
}
]
}
}
]
}
} Or in .NET FeatureManagement schema: {
"FeatureManagement": {
"MyFeature": {
"EnabledFor": [
{
"Name": "Microsoft.Targeting",
"Parameters": {
"Audience": {
"Users": ["Jeff"]
}
}
}
]
}
}
} |
@bdscarboro1 Does this example help you? |
Yes, it did help me, thank you!
…On Wed, May 15, 2024, 2:02 AM Zhiyuan Liang ***@***.***> wrote:
@bdscarboro1 <https://github.com/bdscarboro1> Does this example help you?
—
Reply to this email directly, view it on GitHub
<#446 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/BH6IXGF4IJJU4ZLODXVVPM3ZCL253AVCNFSM6AAAAABHNP4UUCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMJRGY2DONBYGA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
FeatureManagementBuilder is internal, so cannot instantiate from a class library project, which in turn means cannot do the equivalent of this setup from a web api project:
builder.Services.AddFeatureManagement() .WithTargeting<HttpContextTargetingContextAccessor>();
Are there code samples anywhere on how to use Microsoft.FeatureManagement from a class library?
The text was updated successfully, but these errors were encountered: