Skip to content

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

Merged
merged 5 commits into from
Jul 15, 2024

Conversation

rossgrambo
Copy link
Contributor

Why this PR?

  1. Addresses issues
    a. Add Default Http Targeting Context Accessor #415
  2. Updates FeatureFlagDemo example to use the new extension

Visible Changes

Developers using ASP.NET will now have a new extension method available to them, WithTargeting(). Previously, they could only use WithTargeting<ITargetingContextAccessor>()

builder.Services.AddFeatureManagement()
    .WithTargeting()

This default accessor will extract the targeting info from HttpContext.User. Groups will be extracted from claims of type Role. UserId is taken from the Identity.Name field.

/// </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)
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

@rossgrambo rossgrambo Jul 2, 2024

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>()

Copy link
Member

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

Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Member

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.

@zhiyuanliang-ms
Copy link
Contributor

This is a new feature. After this is released, we need to update our public doc to introduce it.

@@ -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.
Copy link
Member

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?

Copy link
Member

@jimmyca15 jimmyca15 Jul 10, 2024

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point- how about:

Suggested change
/// 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.

?

Copy link
Member

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.

@zhiyuanliang-ms
Copy link
Contributor

@jimmyca15 @rossgrambo After this PR is merged, I think we can publish a new stable release. What do you think?

@rossgrambo
Copy link
Contributor Author

Sounds good to me.

There was an issue with the build not starting. Should be fixed now, so I'll merge shortly.

@rossgrambo rossgrambo merged commit 138a4e2 into main Jul 15, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants