What happens of Program.Main when an ASP.NET Core application is run on IISIntegration?

asp.net-core c# entity-framework-core

Question

I'm developing an ASP.NET Core application that will be hosted behind IIS using IISIntegration. In the past, I've already developed a few ASP.NET Core apps, but all of them have been hosted in a Windows service, with IIS acting as a reverse proxy through URL rewriting. Now instead I have to use AspNetCoreModule.

I'm wondering what happens to Program.Main(). Specifically, I call EntityFrameworkCore's EnsureCreated() there, before building the web host. However, even though my application launches correctly and even responds to requests, the database was not populated with the necessary tables.

How can I solve this problem?

1
0
1/19/2019 5:57:31 PM

Accepted Answer

since there is a bit more to it i decided to add the rest of the code i used for it

var scopeFactory = app.ApplicationServices.GetRequiredService<IServiceScopeFactory>();
        using (var scope = scopeFactory.CreateScope())
        {
            var db = scope.ServiceProvider.GetRequiredService<DbContext>();
            db.Database.Migrate();
        }
1
1/19/2019 7:54:12 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow