Accessing database from within GetLocalServiceProviderConfigurationAsync(string configurationID)

Hi,
This isnt strictly a Componentspace question, but it’s a requirement so we can use the dynamic config from the database.

We are implementing the CustomConfigurationResolver and need to access our SQL Server database from within this method, which resides in the startup.cs class.

public override Task GetLocalServiceProviderConfigurationAsync(string configurationID)

The problem is we can’t work out how to access our databse (DBContext) in this method as it’s usually injected via DI after being configured in the ConfigureServices method in the same class, but it’s not available in startup.cs (where the custom resolver code resides) outside of the ConfigureServices or Configure methods.

Once we solve that, our plan is to retrieve the corresponding IdP and SP config information using the configurationId from the database so they can be used during the asp.net core ChallengeResult call for SSO.

Thanks for any help in advance.




I recommend placing your CustomConfigurationResolver in a separate file. We included our example in the Startup file as it is relatively small and we wanted to ensure people saw this option.

You can use DI to inject your DbContext into the CustomConfigurationResolver. For example:


public CustomConfigurationResolver(YourDbContext dbContext)
{
_dbContext = dbContext;
}



Please note that the configurationID supports multiple SAML configurations. Typically this is used in multi-tenancy environments. For more information, please refer to the Configuration Guide.

https://www.componentspace.com/Forums/8234/Configuration-Guide

[quote]
ComponentSpace - 8/3/2021
I recommend placing your CustomConfigurationResolver in a separate file. We included our example in the Startup file as it is relatively small and we wanted to ensure people saw this option.

You can use DI to inject your DbContext into the CustomConfigurationResolver. For example:


public CustomConfigurationResolver(YourDbContext dbContext)
{
_dbContext = dbContext;
}



Please note that the configurationID supports multiple SAML configurations. Typically this is used in multi-tenancy environments. For more information, please refer to the Configuration Guide.

https://www.componentspace.com/Forums/8234/Configuration-Guide
[/quote]

Sometimes you can't see the wood from the trees!
Thank you so much - 5* service as usual!


You’re very welcome!