Setup Application Insights to instrument telemetry into your application.
builder.Services.AddApplicationInsightsTelemetry();
Connect your application to App Configuration, which supplies feature flags and other configurations to your application.
builder.Configuration.AddAzureAppConfiguration(options =>
{
options.Connect(new Uri(endpoint), new DefaultAzureCredential());
});
Add Feature Management to the service collection and add the targeting middleware. Learn More
builder.Services.AddFeatureManagement()
.WithTargeting()
.AddApplicationInsightsTelemetry();
app.UseMiddleware<TargetingHttpContextMiddleware>();
Use DI to retrieve the FeatureManager, and get the assigned variant of the feature flag for the user. Use DI to get an instance of FeatureManager for flag data and TelemetryClient for custom events.
Variant variant = await _featureManager
.GetVariantAsync("MyFeatureFlag", HttpContext.RequestAborted);
telemetryClient.TrackEvent("checkout");