dotnet / Scaffolding

Code generators to speed up development.
MIT License
640 stars 228 forks source link

Why do I need to install EntityFrameworkCore package for scaffolding a page? #1437

Open thomaslevesque opened 4 years ago

thomaslevesque commented 4 years ago

Steps to reproduce:

Run this command on a project that isn't using EntityFramework Core

dotnet aspnet-codegenerator identity --files Account.ExternalLogin

Expected behavior:

It should scaffold the ExternalIdentity page

Actual behavior:

It tells me to install these two packages:

But I'm not using EF Core... I'm using a custom UserStore and RoleStore (based on Cosmos DB) And anyway, this page doesn't use EF Core at all, so there's no need for these packages

Additional information about the project being scaffolded, such as:

Target framework(s):

.NET Core 3.1

Package version of Microsoft.AspNetCore.App or Microsoft.AspNetCore.All (if applicable):

3.1.9

Package version of Microsoft.VisualStudio.Web.CodeGeneration.Design - this may be added to your project by scaffolding:

3.1.4

thomaslevesque commented 4 years ago

Also, why does it generate AuthPadIdentityDbContext and IdentityHostingStartup? I only asked for ExternalLogin!

BrightSoul commented 3 years ago

+1 Since ASP.NET Core Identity does not require EFCore, the scaffolding tool should NOT as well. I'm using a custom implementation of IUserStore<TUser> in a project that's based on ADO.NET and I was forced to install those packages @thomaslevesque mentioned, only to remove them right after the scaffolding was done.

The tool should allow a --userStore parameter or, better yet, a --userClass parameter which is really the only essential requirement for scaffolding. Example:

dotnet aspnet-codegenerator identity --userClass "MyProject.Model.MyUserClass, MyProject" --files Account.ExternalLogin

Also, when the UI needs to get/set informations from the user class, such as the email address, it should go through the UserManager which, in turn, will call the underlying UserStore since it's the one implementing IUserEmailStore and thus contains the proper get/set logic. Right now, instead, the UI requires the user class to derive from IdentityUser as you can see here. It assumes the UserName and Password exist in the user class, which might not be the case.

https://github.com/dotnet/Scaffolding/blob/15a3ffb81fff4dfd9cbe689f33a7ba63108dae69/src/VS.Web.CG.Mvc/Templates/Identity/Bootstrap4/Pages/Account/Account.Register.cs.cshtml#L96