-
Notifications
You must be signed in to change notification settings - Fork 208
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
Example code without BuildWebHost
breaks Entity Framework 2.0
#10
Comments
Hi Jan-Pieter, thanks for the report. Do you mean that a method called Thanks again! |
Hi Nick! Yep, the BuildWebHost needs to exists, that's what it ended up as. The unbelievable bit was what made it cost so much time, I never thought this was the issue and compared a working sample and a not-working app, and brought them closer and closer until this was the only difference. For reference: dotnet/efcore#9415 (comment) Single LOC change might be difficult as the Configuration also needs to be callable from that static bit as well as the normal flow. |
Wow, thanks for the links, that's frankly one of the strangest design points I've seen in an ORM to date. Would love to know the backstory. I'll take a look at the sample again 👍 |
@janpieterz I've updated the example in the main |
Nice. Yeah, I'd be curious what the MS team has to say about this. We could look to set a private static variable that a private static IConfiguration _cachedConfig;
private static IConfiguration GetConfiguration()
{
if (_cachedConfig == null)
{
_cachedConfig = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.Build();
}
return _cachedConfig;
}
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseConfiguration(GetConfiguration())
.UseSerilog()
.UseStartup<Startup>()
.Build(); |
BuildWebHost
breaks Entity Framework 2.0
I also wasted a couple of hours on this one. The fact that the method needs to be called
If you intitialize your database before the |
Thanks for jumping in, @RehanSaeed 👍 .. The sample is now updated ( #17 ) so I'll close this - I think it'd be a great topic for a blog post, which might be a better candidate for top Google result for "serilog entity framework core" than we can achieve with the README. Cheers! |
Took me half a morning before I figured out what was exactly going on.
My Identity Server project used the provided way here to create the host, but Entity Framework relies on the
BuildWebHost
method to analyse it for contexts.Let me know if you'd like me to change the sample and docs here to below, I believe it contains all that's needed for a valid Serilog + AspNetCore flow.
Program.cs:
The text was updated successfully, but these errors were encountered: