为什么 IdentityUser class 在 Microsoft.AspNet.Identity.EntityFramework 命名空间中而不是在核心包中?

Why is the IdentityUser class in the Microsoft.AspNet.Identity.EntityFramework namespace and not in the Core package?

为什么 IdentityUser class 在 Microsoft.AspNet.Identity.EntityFramework 包中而不是包含在 Microsoft.AspNet.Identity.Core 包中?

为什么要依赖EntityFramework?好像很简单class.

我错过了什么?

我通常将数据层与我的 DAL 分开。为 IdentityUser class 添加对 EntityFramework 的依赖似乎有点多。

你问过:

Why is the IdentityUser class in the Microsoft.AspNet.Identity.EntityFramework package...Why should it depend on EntityFramework?

这是因为开箱即用的 Identity 实现实际上取决于 Entity Framework。

ASP.NET 站点有以下文章: Overview of Custom Storage Providers for ASP.NET Identity 表示:

By default, the ASP.NET Identity system stores user information in a SQL Server database, and uses Entity Framework Code First to create the database. For many applications, this approach works well. However, you may prefer to use a different type of persistence mechanism, such as Azure Table Storage, or you may already have database tables with a very different structure than the default implementation. In either case, you can write a customized provider for your storage mechanism and plug that provider into your application.

同一页面还应在有关创建 IUser 的自定义实现的评论中回答您的问题:

Customize the user class

When implementing your own storage provider, you must create a user class which is equivalent to the IdentityUser class in the Microsoft.ASP.NET.Identity.EntityFramework namespace:

Identity 的核心设计未耦合到 EF 或任何特定形状的用户和角色类型。一切都被商店抽象化了。事实上,对于任何给定的持久性提供者,类型甚至根本不需要是 POCO!

对于 Identity 3.0,我们考虑过将我们当前的类型放在核心中(事实上,在某些时候我们已经把它们放在那里了)但是我们从熟悉其他持久性框架的人那里得到了非常可靠的反馈,尽管这些类型可以遵守一个共同的"POCO" 的定义,它们是非常特定于 EF 的。

我们还考虑在核心中包含基础 类,我们将在 EF 包中为 EF 进行扩展。我们降落在我们现在所在的地方,因为这似乎没有足够的好处。这是在增加额外的继承层的复杂性(更多的复杂性会使我们更容易引入错误)与类型本身并不那么复杂以及想要将它们作为起点欢迎复制粘贴代码