Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configure services depending on the enabled feature #35

Closed
VladimirLevchuk opened this issue Dec 12, 2019 · 4 comments
Closed

Configure services depending on the enabled feature #35

VladimirLevchuk opened this issue Dec 12, 2019 · 4 comments

Comments

@VladimirLevchuk
Copy link

Hi,

What's the correct way to checking whether feature enabled from Startup.ConfigureServices?

I'd expect something like
services.AddForFeature(MyFeatures.RedisCache, x => x.Decorate<IMyService, MyCachedService>());

or
if (configuration.IsFeatureEnabled(MyFeatures.RedisCache)) { services.Decorate<IMyService, MyCachedService>(); }

but have not found a nice way of doing it. Have I missed something existing for this? Or such usage breaks design somehow?

@jimmyca15
Copy link
Member

It breaks the pattern a bit because that would be attempting to consume the feature manager before the service provider has been built. Right now there is no clean built-in way to do this, you would have to build an intermediate service provider which is not a good approach.

By the way, are you looking for something similar to what is discussed in this issue Azure/AppConfiguration#68 ?

@VladimirLevchuk
Copy link
Author

Sorry for late response, correct, it's a duplicate of the existing #39

@qin-guan
Copy link

hi, i have this code:

        services.AddHttpClient("ApiServices",
                    c => { c.BaseAddress = new Uri(Urls.ApiUrl); })
                .ConfigurePrimaryHttpMessageHandler(() =>
                {
                    if (disableSslCertValidation)
                    {
                        return new HttpClientHandler
                        {
                            ServerCertificateCustomValidationCallback =
                                (message, certificate, chain, sslPolicyErrors) => true
                        };
                    }
                    return new HttpClientHandler();
                })
                .AddTypedClient(RestService.IFor<ApiServices>);

which would need to use feature management in Startup.cs, is there a way to do this? it seems similar to the issue @VladimirLevchuk mentioned

@rossgrambo
Copy link
Contributor

Closing as a duplicate of #39

@rossgrambo rossgrambo closed this as not planned Won't fix, can't repro, duplicate, stale May 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants