Skip to content
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: Allow IDesignTimeDbContextFactory to short-circuit service provider creation #9076

Closed
ajcvickers opened this issue Jul 5, 2017 · 11 comments

Comments

@ajcvickers
Copy link
Member

commented Jul 5, 2017

Implement some way to specify/find a DbContext and IDesignTimeDbContextFactory such that BuildWebHost is never called even if it is present. This should allow a clean escape hatch to be used when building the service provider has side effects that the app needs to prevent.

See discussion in #9033

@bricelam

This comment has been minimized.

Copy link
Member

commented Jul 6, 2017

Workaround

To prevent EF Core from calling Program.BuildWebHost(), rename it.

@aghe

This comment has been minimized.

Copy link

commented Jul 6, 2017

Just comment what is in Configure() from Startup when you use the tools for migrations.

@bricelam

This comment has been minimized.

Copy link
Member

commented Jul 6, 2017

Is there an issue in Hosting that we should report here? If we only ever access the service provider from the IWebHost, why is it calling Startup.Configure()?

@aghe

This comment has been minimized.

Copy link

commented Jul 6, 2017

From what I see at a quick look on the code BuildWebHost will always call that.

There is a method there seems that is called in BuildWebHost

private static ConfigureBuilder FindConfigureDelegate(Type startupType, string environmentName)
    {
      return new ConfigureBuilder(StartupLoader.FindMethod(startupType, "Configure{0}", environmentName, typeof (void), true));
    }

Maybe I'm wrong

@divega

This comment has been minimized.

Copy link
Member

commented Jul 6, 2017

@bricelam AFAIR there was a conversation about this around the preview 1 timeframe when there was an exception thrown because there was no certificate to run the web host in production mode. Our general feedback was that the call to .Build() was doing way too much work eagerly which intuitively seemed to belong in .Run().

If this doesn't change .Build() will still really be a poor choice of an entry point for design time.

@glennc said he would follow up on that. Not sure if issues have been filed.

@ajcvickers

This comment has been minimized.

Copy link
Member Author

commented Jul 7, 2017

@divega to follow up with @glennc and/or hosting.

@bricelam bricelam changed the title Allow IDesignTimeDbContextFactory to short-circuit service provider creation Design: Allow IDesignTimeDbContextFactory to short-circuit service provider creation Sep 8, 2017

@hikalkan

This comment has been minimized.

Copy link

commented Nov 22, 2017

I have a seed code on Startup.cs file which throws exception since there is no database. It should not run Program.cs if there is a IDesignTimeDbContextFactory implementation.

@ajcvickers

This comment has been minimized.

Copy link
Member Author

commented Jan 27, 2018

Note from triage: this hasn't shown itself to be a major problem so far, so we are closing this issue for now. If you hit this then please provide some feedback on this issue and we will re-assess based on the feedback.

@ajcvickers ajcvickers closed this Jan 27, 2018

@ajcvickers ajcvickers removed this from the 2.1.0 milestone Jan 27, 2018

@Jarrich

This comment has been minimized.

Copy link

commented Nov 21, 2018

It's unclear to me how this is not a major problem with an easy fix.

I didn't know or expected this behavior, so every time I ran "dotnet ef database update" all my configuration would load, a connection would be made to my RabbitMQ instances etc etc... causing the migration to fail if something went wrong there.

Please re-consider.

@0xNOP

This comment has been minimized.

Copy link

commented Dec 3, 2018

Can't you just check if there's IDesignTimeDbContextFactory implemented and if not fall back to calling BuildWebhost?

@GreatFireWall

This comment has been minimized.

Copy link

commented Jul 11, 2019

Any solution ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
8 participants
You can’t perform that action at this time.