-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Design: Discover DbContext types using Program.BuildWebHost() #8164
Comments
As part of revisiting |
#7353 may also be related to this work. |
We currently allow a |
Questions we need to answer:
|
Decisions:
Still need to discuss this:
|
We will no longer attempt to call |
After #8314, #8326 & dotnet/templating#705 are merged, the 2.0.0-preview1 work for this item is done. We'll gather feedback and see if we need to do anything more in this area. I'll file a new issue to reflect the work that was done for 2.0.0-preview1 and move this one into 2.0.0 for to follow up. |
Filed #8328 |
Inlining @ajcvickers's comment. Think we need a better message that indicates that this has happened not because they did something "wrong" but because we have made a change in how things work in 2.0. Probably with a fwlink to docs on how to convert. But happy for all this to happen later. |
This has evolved a bit since originally filing. The current plan is to use the interface described in aspnet/DependencyInjection#524 and not try to call |
With #8510, we'll now use |
Is there any good way to know if we're in 'design-time' since you're running the entire Startup path? I can't seem to find how to know if dotnet ef is running us instead of dotnet run. Any ideas> |
Implementing |
So if I have both, it will use IDesignTimeDbContextFactory first if found? |
@shawnwildermuth Not currently, but see #9076, #9033, and #9073. |
@shawnwildermuth Yes. However, per the issues mentioned above, we may still (despite implementing the factory) call Program.BuildWebHost to probe for additional DbContext types in the application service provider. The workaround to avoid this is to |
I talked about my approach (since all the examples I've seen is use the same method to build up the webhost) in my blog. It feel hacky (and I mention it as such). Feel free to burn me a little for this monstrosity. https://wildermuth.com/2017/07/06/Program-cs-in-ASP-NET-Core-2-0 |
If ASP.NET Core adds a well known, static accessor to the
IWebHost
, our tools can use this to instantiate theDbContext
at runtime.We may also want to reconsider some aspects of the previous
Startup
-based mechanism which leaked a bit into our codebase. Specificly: environment and content root directory. This includes the--environment
option ondotnet ef
andef.exe
, theenvironment
andcontentRootPath
parameters onOperationExecutor
, and theContentRootPath
(see also #8159) andEnvironmentName
properties on `DbContextFactoryOptions. Issue #7480 is also probably superseded by this.We may also want to flow arbitrary command-line arguments into the static entry point and
IDbContextFactory
. But I'm not sure how we'll handle the transition from PowerShell to command-line...This work depends on #7588
The text was updated successfully, but these errors were encountered: