I hope this is a simple question:
How can you change 2 connection strings at runtime in the
Global.asax
underApplication_Start()
Web.config
<connectionStrings>
<add connectionString="DB1" value=""/>
<add connectionString="DB2" value=""/>
</connectionStrings>
Global.asax
protected void Application_Start() {
AreaRegistration.RegisterAllAreas();
GlobalConfiguration.Configure(WebApiConfig.Register);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
}
Details
Before I start getting questions as to why I'm doing this or reasons I shouldn't, please refer to the following post Azure Key Vault Connection Strings and N-Layered Design.
Essentially, I'm trying to use Key Vault with an N-Layered application. The WebAPI defines the connection string via the Web.config
. In order to avoid hard-coding connection strings, they will be stored in Key Vault. However, due to the Unit Of Work
pattern used, I'm not sure the best route and I'm currently trying to figure out the potential solution of injecting or changing the connection string at runtime for the Web API project only.