feat(variants): allow in-memory objects - #615
Conversation
|
Hey, Zhiyuan Liang (@zhiyuanliang-ms)! could you take a look please? |
|
My understanding is that this enhancement is intended specifically for the custom feature definition provider scenario. Is that correct? |
yes it is. right now i am implementing a custom provider. i need to do something like this in order to put data from an external storage into the definition: new VariantDefinition
{
Name = "...",
ConfigurationValue =
new ConfigurationBuilder()
.AddInMemoryCollection([new("Value", variantValue.ToString())])
.Build()
.GetSection("Value")
} |
|
And the idea came to me from the |
3ba89be to
90fe16e
Compare
|
Hey, Степан (@Stepami) We discussed this scenario internally, and we agree that supporting in-memory variant values is useful for custom One concern we have is that: for customers using the built-in Before adding a new public property, we would like to think through what the story should be for those customers as well. Ideally, this should feel like a generally useful part of the variant configuration model, rather than an API surface that only applies when a custom provider is used. For example, one question we are considering is whether the built-in provider should also be able to populate an object representation from the configured variant value, or whether there is another API shape that gives both built-in and custom provider users a consistent way to consume variant configuration. |
|
I have been thinking about the following options:
I used to think this is the best option. But after a second look, I realize the conversion will not be lossless. For example, a numeric value could end up being reconstructed as a string.
For example Variant variant = await featureManager.GetVariantAsync("MyFeature");
MySettings settings = variant.Configuration.Get<MySettings>();I am thinking about adding a new extension method to Variant variant = await featureManager.GetVariantAsync("MyFeature");
MySettings settings = variant.GetConfiguration<MySettings>();Or we can even add a new extension method to MySettings settings = await featureManager.GetVariantConfigurationAsync<MySettings>("MyFeature");This can unify the story that people who uses custom feature definition provider with in-memory object and built-in configuration feature defition provider. |
|
hey Zhiyuan Liang (@zhiyuanliang-ms) ! I agree that I'll take a few days to think this through |
|
hey Zhiyuan Liang (@zhiyuanliang-ms) I decided to do both populate the data supplied by the buil-in configuration provider and create the common API used to consume variant configuration through extension method. ConfigurationObjectNow GetConfiguration
I placed the method on |
Why this PR?
Implementing
IFeatureDefinitionProvidermakes it inconvinient to fill variant bound values if they don't come from configuration.Similarly to feature filters I decided to introduce an object that can be used as an alternative
ConfigurationValue. CustomIFeatureDefinitionProviderimplementations can populate this property directly instead of constructing anIConfigurationSectioninstance.Visible Changes
Microsoft.FeatureManagement.VariantDefinition.ConfigurationObjectMicrosoft.FeatureManagement.Variant.ConfigurationObject