Skip to content
This repository has been archived by the owner on Apr 8, 2020. It is now read-only.

Angular CLI-based template: Follow the BuildWebHost convention for better compatibility with EF Design Tools #1434

Closed
andrewjsaid opened this issue Dec 12, 2017 · 2 comments

Comments

@andrewjsaid
Copy link

This issue is based on my comment in #1288

I may have found a regression with the newest template Microsoft.DotNet.Web.Spa.ProjectTemplates::2.0.0-preview1-final.

In older templates, the Program class had a method IWebHost BuildWebHost which has been replaced with IWebHostBuilder CreateWebHostBuilder.

The problem occurs when attempting to run EF migrations dotnet ef migrations add Migration1. The new template causes the following error to appear

Unable to create an object of type 'DbContext'. Add an implementation of 'IDesignTimeDbContextFactory<DbContext>' to the project, or see https://go.microsoft.com/fwlink/?linkid=851728 for additional patterns supported at design time.

Some digging about shows that BuildWebHost is a convention expected by Entity Framework Core Design Tools. see https://github.com/aspnet/Hosting/blob/cda9ec6fe416eaa4fdc8f72276c7b16941d9761c/shared/Microsoft.AspNetCore.Hosting.WebHostBuilderFactory.Sources/WebHostFactoryResolver.cs

There is a solution - which is to expose the IDesignTimeDbContextFactory<DbContext> as suggested in the error message - but it would be easier for everybody if EF Design tools work out of the box.

@SteveSandersonMS
Copy link
Member

SteveSandersonMS commented Dec 13, 2017

Thanks for reporting this. This isn't specific to the new SPA templates - it's the same in all the latest ASP.NET project templates. For example, here's the Program.cs for the default ASP.NET project: https://github.com/aspnet/templating/blob/dev/src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-CSharp/Program.cs. As you'll see, this has CreateWebHostBuilder as well.

The SPA templates are meant to be consistent with the other ASP.NET templates, so if you think this should change, could you report it to the https://github.com/aspnet/templating repo, explaining that you think all the web project templates should change? Or maybe some fix is needed in EF to support the new convention.

@andrewjsaid
Copy link
Author

Thanks for the background. I see that EF integration with the new pattern is already being discussed at aspnet/Templating#78 so no need to follow this up.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants