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
{{ message }}
Repository navigation
Commands: Look for ConfigureServices in Program #3802
I created a Console project and configured it to read the connection string during Startup and the app ran fine as expected. However, when I tried to use migrations using EF.Commands, I got an error saying that no database providers were configured.
To work around that I ended up creating a DbContextFactory which the Commands read and things worked fine.
I was surprised that I had to create the Factory as I do not need to do this for an ASP Web Application. Is this a different behavior for apps other than ASP.NET Web Application and was I right to create the Factory to work around this?
We have some special logic for ASP.NET 5 apps to run the code from startup and then resolve your context from DI.
cc @bricelam who was looking at some improvements so that we could do the same outside of ASP.NET 5... not sure where we got to with those? Note there is a ConfigureServices in Program.
Thanks. Yeah I know that there is ConfigureServices in Program but I still couldn't get the EF Commands to work with just ConfigureServices in Program.
It wasn't until I added the Factory that I could generate Migrations
The behavior is the same everywhere, but the ConfigureServices method still needs to be in a class called Startup. Looking inside Program (and App for XAML apps) came up during the design meeting, but we decided to stick with just Startup everywhere for now.
On Fri, Nov 20, 2015 at 9:15 AM Brice Lambson [email protected]
wrote:
The behavior is the same, but the ConfigureServices method still needs to
be in a class called Startup. Looking inside Program came up during the
design meeting, but we decided to stick with just Startup everywhere for
now.
—
Reply to this email directly or view it on GitHub #3802 (comment)
.
Activity
rowanmiller commentedon Nov 19, 2015
We have some special logic for ASP.NET 5 apps to run the code from startup and then resolve your context from DI.
cc @bricelam who was looking at some improvements so that we could do the same outside of ASP.NET 5... not sure where we got to with those? Note there is a ConfigureServices in Program.
dneimke commentedon Nov 19, 2015
Thanks. Yeah I know that there is ConfigureServices in Program but I still couldn't get the EF Commands to work with just ConfigureServices in Program.
It wasn't until I added the Factory that I could generate Migrations
bricelam commentedon Nov 19, 2015
The behavior is the same everywhere, but the
ConfigureServicesmethod still needs to be in a class calledStartup. Looking insideProgram(andAppfor XAML apps) came up during the design meeting, but we decided to stick with justStartupeverywhere for now.dneimke commentedon Nov 19, 2015
Ahh... got it. Thx
On Fri, Nov 20, 2015 at 9:15 AM Brice Lambson [email protected]
wrote:
dneimke commentedon Nov 20, 2015
I moved all of that code into a Startup.cs and now I no longer need the Factory. Thanks for the help!
FYI, here's the updated code:
https://github.com/dneimke/coffeestore/blob/develop/src/EF7Demo.CoffeeStore/Program.cs
added Startup file which makes the DbContextFactory uneccessary. Refer:
[-]Enabling Migrations in a Console App[/-][+]Commands: Look for ConfigureServices in Program[/+]bricelam commentedon Nov 20, 2015
I've updated the title of this bug to reflect your original expectations so we can discuss it as a team again.
bricelam commentedon Nov 20, 2015
We decided to search in
ProgramandAppin addition toStartup.dneimke commentedon Nov 20, 2015
That's awesome, thanks guys!