-
Notifications
You must be signed in to change notification settings - Fork 127
Use ITargetingContext when calling GetVariantAsync #484
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
Changes from 2 commits
c870ff5
8ea84fb
ea68517
0bdf279
b7a2af8
e6124f6
19e5520
6bcca05
a308916
5a8bf51
5153e88
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -225,10 +225,10 @@ public async ValueTask<Variant> GetVariantAsync(string feature, CancellationToke | |
| /// Gets the assigned variant for a specific feature. | ||
| /// </summary> | ||
| /// <param name="feature">The name of the feature to evaluate.</param> | ||
| /// <param name="context">An instance of <see cref="TargetingContext"/> used to evaluate which variant the user will be assigned.</param> | ||
| /// <param name="context">A context providing information that can used to evaluate which variant the user will be assigned.</param> | ||
|
zhiyuanliang-ms marked this conversation as resolved.
Outdated
|
||
| /// <param name="cancellationToken">The cancellation token to cancel the operation.</param> | ||
| /// <returns>A variant assigned to the user based on the feature's configured allocation.</returns> | ||
| public async ValueTask<Variant> GetVariantAsync(string feature, TargetingContext context, CancellationToken cancellationToken = default) | ||
| public async ValueTask<Variant> GetVariantAsync<TContext>(string feature, TContext context, CancellationToken cancellationToken = default) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't it required for
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While If the user uses a contextual feature filter which requires Previously, we only allow user to pass How about this? If the
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are talking about an edge case where
No, we shouldn't use ambient context in contextual feature evaluation.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I also don't think Variants need to be fully tied to targeting. We don't support it yet- but it seems quite reasonable to want variants without wanting user based allocation. Making it TContext also aligns it with IsEnabled, which is more consistent. IsEnabled is also able to use Allocation in the same way that GetVariant is. So whatever we decide on- the two interfaces should use the same. |
||
| { | ||
| if (string.IsNullOrEmpty(feature)) | ||
| { | ||
|
|
@@ -262,11 +262,11 @@ private async ValueTask<EvaluationEvent> EvaluateFeature<TContext>(string featur | |
|
|
||
| // | ||
| // Determine Targeting Context | ||
| TargetingContext targetingContext; | ||
| ITargetingContext targetingContext; | ||
|
|
||
| if (useContext) | ||
| { | ||
| targetingContext = context as TargetingContext; | ||
| targetingContext = context as ITargetingContext; | ||
| } | ||
| else | ||
| { | ||
|
|
@@ -601,7 +601,7 @@ private async ValueTask<TargetingContext> ResolveTargetingContextAsync(Cancellat | |
| return context; | ||
| } | ||
|
|
||
| private ValueTask<VariantDefinition> AssignVariantAsync(EvaluationEvent evaluationEvent, TargetingContext targetingContext, CancellationToken cancellationToken) | ||
| private ValueTask<VariantDefinition> AssignVariantAsync(EvaluationEvent evaluationEvent, ITargetingContext targetingContext, CancellationToken cancellationToken) | ||
| { | ||
| Debug.Assert(evaluationEvent != null); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,7 +18,7 @@ public class EvaluationEvent | |
| /// <summary> | ||
| /// The targeting context used to evaluate the feature. | ||
| /// </summary> | ||
| public TargetingContext TargetingContext { get; set; } | ||
| public ITargetingContext TargetingContext { get; set; } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd like to keep this as |
||
|
|
||
| /// <summary> | ||
| /// The enabled state of the feature after evaluation. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT license. | ||
| // | ||
| using Microsoft.FeatureManagement.FeatureFilters; | ||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
|
|
||
| namespace Microsoft.FeatureManagement | ||
| { | ||
| /// <summary> | ||
| /// Extensions used to provide an overload for <see cref="IVariantFeatureManager.GetVariantAsync"/> that accepts a <see cref="TargetingContext"/> type directly. | ||
| /// </summary> | ||
| public static class VariantFeatureManagerExtensions | ||
| { | ||
| /// <summary> | ||
| /// Gets the assigned variant for a specific feature. | ||
| /// </summary> | ||
| /// <param name="variantFeatureManager">The <see cref="IVariantFeatureManager"/> instance.</param> | ||
| /// <param name="feature">The name of the feature to evaluate.</param> | ||
| /// <param name="context">An instance of <see cref="TargetingContext"/> used to evaluate which variant the user will be assigned.</param> | ||
| /// <param name="cancellationToken">The cancellation token to cancel the operation.</param> | ||
| /// <returns>A variant assigned to the user based on the feature's configured allocation.</returns> | ||
| public static ValueTask<Variant> GetVariantAsync(this IVariantFeatureManager variantFeatureManager, string feature, TargetingContext context, CancellationToken cancellationToken = default) | ||
| { | ||
| return variantFeatureManager.GetVariantAsync(feature, context, cancellationToken); | ||
| } | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.