You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
That also works but be careful. Using this you're reading from a file (+ deserializing) every time DI decides to create an instance of your DbContext which is probably on every request and maybe more. VERY bad.
You can simply read that in your Startup and store the connection string in a static prop on your DbContext. Yeah this sounds a lot better.
Ah, on second thoughts I see what you did. Calling the migrator won't call Startup. That's why I hard coded it in the first place. I guess we can make a default ctor like yours but write another one with the connection string as an argument that we will register with DI in order to avoid hard coding stuff and also avoid unnecessary performance hits.
You don't need to hard code the connection string in the
DbContext
. I am using the following code:My appSettings.json looks like this:
Works Great!
The text was updated successfully, but these errors were encountered: