Closed rossgrambo closed 4 months ago
If someone has an idea for a shared place for the TargetingContextLookup
string, let me know. I couldn't decide on a clean spot. Decided to leave them as separate strings for now since we're hoping to adjust the caching to not need them anyway.
Just for ideas... you either make it a public property or use InternalsVisibleToAttribute between the two packages. Like you said, none of them are clean ways.
I know adding a scoped service will be an approach that we will want to propose to float the resolved targeting context along, but I also thing we should consider an alternative option -- exposing a public extension method on HttpContext from the Microsoft.FeatureManagement.AspNetCore
package that gets the resolved targeting context.
namespace Microsoft.FeatureManagement.AspNetCore;
public static class HttpContextExtensions
{
//
// Gets the targeting context resolved by feature management during a request.
public static TargetingContext GetTargetingContext(this HttpContext httpContext);
}
@jimmyca15 @rossgrambo Are we going to include this PR into the next preview release (preview3)?
Would be nice- but I don't think it's a blocker.
Is there a plan to use this built-in targeting context accessor in our FeatureFlagDemo example? (include the change in this PR or create a new PR after this PR is merged?)
Is there a plan to use this built-in targeting context accessor in our FeatureFlagDemo example? (include the change in this PR or create a new PR after this PR is merged?)
Yes, I'm planning on a separate PR to update examples.
There have been some developments as we have discussed the middleware and telemetry initializer across different PRs/issues. My expectation at this point is that:
private object _targetingContextKey = new object();
As such, I don't expect any changes in the middleware/initializer as part of this PR.
As such, I don't expect any changes in the middleware/initializer as part of this PR.
Agreed. This PR is on hold until the caching rework is completed.
This PR has been dissolved into two:
main
Why this PR?
Next Steps:
Visible Changes
Developers will now have a new type available to them,
DefaultHttpTargetingContextAccessor
. Instead of defining their own, they can use this type when adding targeting viaWithTargeting
like:The default accessor will extract the targeting info from
HttpContext.User
.Groups
will be extracted from claims of typeRole
.UserId
is taken from theIdentity.Name
field.