-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use ITargetingContext when calling GetVariantAsync (#484)
* add variant feature manager extensions * use TContext to avoid future breaking change * TargetingContext in EvaluationEvent * update comments & not use ambient context in contextual case * update comment * use ITargetingContext & check runtime context type * use TargetingCotnext for private method * use var instead of type * revert change on ContextualTestFilter * update comment * update comment
- Loading branch information
1 parent
882c7b7
commit 9284d27
Showing
9 changed files
with
135 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
src/Microsoft.FeatureManagement/VariantFeatureManagerExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 for <see cref="IVariantFeatureManager"/>. | ||
/// </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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,17 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
// | ||
using Microsoft.FeatureManagement.FeatureFilters; | ||
using System.Collections.Generic; | ||
|
||
namespace Tests.FeatureManagement | ||
{ | ||
class AppContext : IAccountContext | ||
class AppContext : IAccountContext, ITargetingContext | ||
{ | ||
public string AccountId { get; set; } | ||
|
||
public string UserId { get; set; } | ||
|
||
public IEnumerable<string> Groups { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters