Conditionally register authentication service in Startup.cs based on another service

Viewed 21

This is a bit of a continuation of my previous question located here. I've successfully been able to add the OpenIdConnect authorization to Startup.cs. Now, I'm looking for a way to conditionally disable it based on another service that I configure, which has various configuration options (one of which is to enable or disable the OpenIdConnect authorization).

From various other threads, I've seen ways of injecting services to configure the options for the authorization - for example, this one. However, none of these allow me to conditionally register the service itself.

The best example I could find would be to use services.BuildServiceProvider().GetService() to get a list of the services that I've registered prior to this, and then get the specific service I'm looking for. Before I go down that path though, I wanted to see if there were any other options available.

0 Answers
Related