microsoft / FeatureManagement-Dotnet

Microsoft.FeatureManagement provides standardized APIs for enabling feature flags within applications. Utilize this library to secure a consistent experience when developing applications that use patterns such as beta access, rollout, dark deployments, and more.
MIT License
1.06k stars 115 forks source link

Feature-based Injection #335

Closed zhiyuanliang-ms closed 9 months ago

zhiyuanliang-ms commented 11 months ago

This PR is targeting on the potential user case is to inject services based on variants. For example, if the variant was an algorithm name, and a controller constructor took IHashAlgorithm as a constructor parameter. How could we make it so that the implementation was dependent upon an assigned variant?

Also, it tries to resolve #39.

This draft PR provides one APIs: FeatureManagementBuilder.AddFeaturedService<TService>

Example usage can be found here: examples/FeatureBasedInjectionPOC/Program.cs

Open to suggestion for the design of feature-based injection.

zhiyuanliang-ms commented 9 months ago

An exception should be thrown if there are multiple IVariantServiceProvider<TService> being registered.