-
Notifications
You must be signed in to change notification settings - Fork 120
Adds Default Targeting Accessor and extension method WithTargeting #466
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
Conversation
…riation for ASP.NET
/// </summary> | ||
/// <param name="builder">The <see cref="IFeatureManagementBuilder"/> used to customize feature management functionality.</param> | ||
/// <returns>A <see cref="IFeatureManagementBuilder"/> that can be used to customize feature management functionality.</returns> | ||
public static IFeatureManagementBuilder WithTargeting(this IFeatureManagementBuilder builder) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we call AddHttpContextAccessor
in this method since our default targeting accessor depends on it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a great question. I originally thought no- so we're in parity with what we have today. However it would remove another hurdle to get started so I think it's a good idea.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to decouple that.
By the way, is this method name the one that we discussed so many options and couldn't settle on one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, let's keep it decoupled. Could always do that in a separate PR anyway.
By the way, is this method name the one that we discussed so many options and couldn't settle on one?
Yes it is. The last design review it was discussed up was the caching meeting last month. We lightly aligned on .WithTelemetry<DefaultTargetingContextAccessor>()
, but some smaller discussion afterwards lead to .WithTelemetry()
so we didn't have to make DefaultTargetingContextAccessor
public.
Although I'm having trouble finding a paper trail to confirm that we did commit to this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zhenlan do you have thoughts on the .WithTelemetry()
WithTargeting()
over .WithTargeting<DefaultTargetingContextAccessor>()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this would have been referring to WithTargeting
, not WithTelemetry
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would a blazor user take a dependency on this package and see this method? My thought is that if we go with WithTargeting, any application that would depend on this package should most likely use this method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My fault- yes .WithTargeting
.
Blazor Webassembly is just a client side thing- so it would work fine with an ASP.NET backend requiring this.
Blazor Server would not work as expected- and I wouldn't expect the dev to use the ASP.NET package. Although- Blazor Server are built on top of ASP.NET Core so it's not unreasonable a developer would try this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could add it by default if 1) it will not break any existing applications and 2) users can easily override it if they want to use their own targeting context accessor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, having it with just WithTargeting
sounds reasonable to me.
This is a new feature. After this is released, we need to update our public doc to introduce it. |
src/Microsoft.FeatureManagement.AspNetCore/DefaultHttpTargetingContextAccessor.cs
Outdated
Show resolved
Hide resolved
@@ -44,5 +47,28 @@ public static IFeatureManagementBuilder UseDisabledFeaturesHandler(this IFeature | |||
|
|||
return builder; | |||
} | |||
|
|||
/// <summary> | |||
/// Adds the <see cref="DefaultHttpTargetingContextAccessor"/> to be used for targeting and registers the targeting filter to the feature management system. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's an internal type. It shouldn't show up in a public method summary. The compiler allows it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since DefaultHttpTargetingContextAccessor
is internal, users won't see its class summary so some of those details would be useful here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point- how about:
/// Adds the <see cref="DefaultHttpTargetingContextAccessor"/> to be used for targeting and registers the targeting filter to the feature management system. | |
/// Adds the default ASP.NET <see cref="ITargetingContextAccessor"/> to be used for targeting and registers the targeting filter to the feature management system. |
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would say something like.
Enables the use of targeting within the application and adds a targeting context accessor that extracts targeting details from a request's HTTP context.
@jimmyca15 @rossgrambo After this PR is merged, I think we can publish a new stable release. What do you think? |
Sounds good to me. There was an issue with the build not starting. Should be fixed now, so I'll merge shortly. |
Why this PR?
a. Add Default Http Targeting Context Accessor #415
Visible Changes
Developers using ASP.NET will now have a new extension method available to them,
WithTargeting()
. Previously, they could only useWithTargeting<ITargetingContextAccessor>()
This 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.