I have Entity Framework DbContext like this
class MyClassDBContext:DBContext,IMyClassDBContext
{
public MyClassDBContext() : base(str, true)
{
this.Database.Connection.ConnectionString = str;
}
}
This works well. I also use Unity framework to add dependency injection of this class to other layers i.e business layer using web.config
like this:
<register type="IMyClassDBContext" mapTo="MyClassDBContext">
<lifetime type="perRequestLifetimeManager" />
</register>
Now, I want to find a way to inject the connection str
at runtime into the DbContext
using Unity. I can get the connection string from Azure KeyVault in startup, but not really sure how I can inject in the Entity Framework constructor.
This is a Web API project with Entity Framework 6