Click here to Skip to main content
15,613,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
We have a scenario where the config data changes for different users. So we need to fetch config data on every api call from DB.

What I have tried:

In earlier design we have
in ConfigureServices under Startup.cs and corresponding code to load config info from appsettings.json file like this:
services.Configure<GoOrdRWebAPI_ConfigurationSetting>(x => configuration.GetSection("GoOrdRWebAPISettings").Bind(x));

Call just requires DI and simple call like this:
string constr = _configs.Value.CentralMySqlConnection;

But now since config info will have to change for every api call ,we cant fetch from appsettings.json.

We tried adding config object from middleware to HttpContext.Request.Headers like this:
ConfigModel conMod = GetConfigDataToContext();
context.Request.Headers.Add("config_data", JsonConvert.SerializeObject(conMod));

But this doesn't seem very secure and handy.
Is there a better way to do this? Preferably something similar to what we did originally(via IServiceCollection) but from Middleware instead of Startup.cs?
Gerry Schmitz 2-Jun-21 12:46pm    
You're heading implies "how do I" when in fact you have a solution but just don't like it. Say so.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900