support variant service match mode#607
Conversation
| string implementationName = ((VariantServiceAliasAttribute)Attribute.GetCustomAttribute(implementationType, typeof(VariantServiceAliasAttribute)))?.Alias; | ||
| if (_serviceProvider is IKeyedServiceProvider) | ||
| { | ||
| TService keyedService = _serviceProvider.GetKeyedService<TService>(enabled); |
There was a problem hiding this comment.
what if i want to register my feature services against other keys?
There was a problem hiding this comment.
I didn't test it. But my expectation is that you can register the same service multiple times using different keys,
There was a problem hiding this comment.
I'm trying to tell that if I want to use some key other than the feature status the variant sp won't get my impl as it doesn't know and can't know it.
The point is for VariantSp to be able to resolve my service not just with boolean key but any user-provided one
There was a problem hiding this comment.
Hey, @Stepami This is a valid call. The solution we are considering is that:
Remove the VariantServiceMatchMode
Introduce a new VariantServiceProviderOptions (the name is not decided)
Service.AddFeatureManagement()
.WithVariantService<TService>("MyFeature", new VariantServiceProviderOptions()
{
EnabledKey (NTD, we can have a better name) = "VariantServiceA", // work as fallback, pnly take effect where there is no variant allocated
DisabledKey = "VariantServiceB"
});What do you think about this?
There was a problem hiding this comment.
Yeah, i think that's right direction into flexibility. But i also liked the idea of feature status value as default key if there's none from user. Maybe we could do some static factory methods, like:
VariantServiceProviderOptions.Variant()
VariantServiceProviderOptions.Status() // same as Status(enabledKey: true, disabledKey: false)
VariantServiceProviderOptions.Status(enabledKey: "VariantA", disabledKey: "VariantB")There was a problem hiding this comment.
The existing options in this library: FeatureManagementOptions and TargetingEvaluationOptions. We don't have the pattern like Options.XXX()
My preference would be to keep the options class property-based, this is more common in .NET
We can have default value for EnabledKey and DisabledKey
But, the feature flag status matching will be the fallback. If variant is not null and the name can match any implementation, that implementation will be returned. Variant has higher priority than flag status during the service matching.
There was a problem hiding this comment.
But, the feature flag status matching will be the fallback. If variant is not null and the name can match any implementation, that implementation will be returned. Variant has higher priority than flag status during the service matching.
Yeah it's totally makes sense considering that the old schema is the fallback
|
Integrated to #606 |
Why this PR?
A follow up PR for #606, trying to resolve #604
Today
VariantServiceProvider<T>only selects an implementation based on the assigned variant name. This PR adds an alternative mode where the implementation is selected based on the feature flag's enabled status (true/false), useful when a feature has no variants (e.g. a simple toggle flag).Introduce
VariantServiceMatchModeenum which hasVariant(default) andStatusvalue.Usage:
Note that the

AddKeyed*family takes object? serviceKey, not just string.