Is there a good way to get the ServiceProvider in the AddOpenIdConnect, or configure the ClientSecret later where we have the DI container fully setup? (e.g. in Configure(IApplicationBuilder app))
We're getting the client secret from somewhere else and we like to use DI for that.
Minimal working example
Currently we do this, but I really like to remove services.BuildServiceProvider()
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddOpenIdConnect(AuthenticationScheme, options =>
{
ServiceProvider serviceProvider = services.BuildServiceProvider(); // we like to prevent this
options.ClientSecret = serviceProvider.GetRequiredService<ISecretRetriever>().GetClientSecret();
Note: For events like OnValidatePrincipal we could get it from CookieValidatePrincipalContext.HttpContext.RequestServices
We get also now this warning:
warning "Calling 'BuildServiceProvider' from application code results in a additional copy of Singleton services being created"
Question
Is there a good way to get the
ServiceProvider
in theAddOpenIdConnect
, or configure the ClientSecret later where we have the DI container fully setup? (e.g. inConfigure(IApplicationBuilder app)
)We're getting the client secret from somewhere else and we like to use DI for that.
Minimal working example
Currently we do this, but I really like to remove
services.BuildServiceProvider()
Note: For events like OnValidatePrincipal we could get it from
CookieValidatePrincipalContext.HttpContext.RequestServices
We get also now this warning: