Feature filter parameter object#589
Conversation
| TargetingFilterSettings settings = (TargetingFilterSettings)context.Settings ?? (TargetingFilterSettings)BindParameters(context.Parameters); | ||
| // Check if ParameterObject available (takes precedence), then prebound settings, otherwise bind from parameters. | ||
| TargetingFilterSettings settings = context.ParameterObject != null | ||
| ? (TargetingFilterSettings)context.ParameterObject |
There was a problem hiding this comment.
Consider the exception that will be raised by the system if someone provides the incorrect type here. Ideally we'd like a FeatureManagementException if someone populates ParametersObject, but it's not TargetingFilterSettings
There was a problem hiding this comment.
Got it. Added FeatureManagementError.InvalidParametersObject for this scenario.
There was a problem hiding this comment.
Discussed offline, throw ArgumentException for incorrect type.
|
Copilot's findings of "This assignment to parametersObject is useless, since its value is never read." are valid and should be addressed before merging. |
| { | ||
| FeatureName = featureDefinition.Name, | ||
| Parameters = featureFilterConfiguration.Parameters, | ||
| ParametersObject = featureFilterConfiguration.ParametersObject, |
There was a problem hiding this comment.
Can we set ParametersObject to FeatureFilterEvaluationContext.Settings instead of adding a new ParametersObject property.
There was a problem hiding this comment.
I think that's a good idea. We'll need an update on the description of Settings. Something like
/// <summary>
/// A settings object, if any, provided for the feature filter to use when evaluating whether the feature should be enabled.
/// This property is populated in two cases:
/// For features that provide parameters as an object.
/// For <see cref="IFeatureFilter"/>s that implement <see cref="IFilterParametersBinder"/>.
/// </summary>
|
|
||
| // | ||
| // Check if prebound settings available, otherwise bind from parameters. | ||
| TimeWindowFilterSettings settings = (TimeWindowFilterSettings)context.Settings ?? (TimeWindowFilterSettings)BindParameters(context.Parameters); |
There was a problem hiding this comment.
If we set the new parametersObject to context.settings, the code path will be more unified.
Overview
This PR introduces a new
ParameterObjectproperty toFeatureFilterEvaluationContext, enabling customIFeatureDefinitionProviderimplementations to supply feature filter settings directly without requiringIConfiguration.Motivation
Currently, feature filters receive their configuration through
IConfiguration, which works well for JSON/config file-based feature definitions. However, customIFeatureDefinitionProviderimplementations that source feature definitions from alternative backends (e.g., databases, REST APIs, gRPC services) are forced to:IConfigurationobject from their native data formatThis round-trip is unnecessary overhead when the provider already has the ability to create strongly-typed settings objects like
TargetingFilterSettingsorTimeWindowFilterSettingsdirectly.Code Examples - Before & After
Before: Using
IConfigurationwithInMemoryCollectionWhen implementing a custom
IFeatureDefinitionProviderthat fetches feature definitions from a database, you previously had to construct anIConfigurationobject to pass filter parameters:This approach has several drawbacks:
After: Using
ParameterObjectDirectlyWith the new
ParameterObjectproperty, custom providers can supply strongly-typed settings directly:Changes
FeatureFilterEvaluationContext: AddedParameterObjectproperty to hold strongly-typed settings provided by custom providersPercentageFilter,TimeWindowFilter,ContextualTargetingFilter): Now checkParameterObjectfirst before falling back toSettingsor binding fromParametersPrecedence Order
When evaluating filter settings:
ParameterObject(if set) — Direct strongly-typed object from providerSettings— Pre-bound settings viaIFilterParametersBinderParameters— Bind fromIConfigurationThe expectation is that systems using
ParameterObjectwill not setParameters/IConfiguration.