Aspnetcore.docs: We could use EnsureCreatedAsync using async Main

Created on 12 Apr 2020  Â·  5Comments  Â·  Source: dotnet/AspNetCore.Docs

In .NET Core > 2.1, async Task Main can be used instead, then EnsureCreatedAsync could be used.

I find it really important to point that out in the docs, because many people are looking for ways to initialize post-build app stuff, that are many times asynchronous.

Here's an example question in SO.

Created PR #17750.


Document Details

⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

Source - Docs.ms

Most helpful comment

@ajcvickers please review. We should probably update the doc's with best practice.

All 5 comments

EnsureCreatedAsync is not suitable for production apps.

Can you please explain why?

@ajcvickers please review. We should probably update the doc's with best practice.

@Rick-Anderson @weitzhandler As part of the plan for EF Core 5, we are investigating better experiences for migrating the database that don't involve running migrations from code--see https://github.com/dotnet/efcore/issues/19587. This will likely result in something like "migration bundles" that can easily be deployed at the same time as the database. We also have https://github.com/dotnet/efcore/issues/20402 which is about integrating this into something like the ASP.NET Core error page middleware.

With regard to the associated PR, the async change is probably marginally better than what we have now, but we need to revisit this after we have got further along the bundles path.

/cc @JeremyLikness @bricelam

Async doesn't really help in this situation. The application isn't accepting requests at this point. There is effectively only one thread running and yielding it will probably only make it take longer to start up and begin accepting requests.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

serpent5 picture serpent5  Â·  3Comments

danroth27 picture danroth27  Â·  3Comments

fabich picture fabich  Â·  3Comments

nenmyx picture nenmyx  Â·  3Comments

Raghumu picture Raghumu  Â·  3Comments