将ASP.NET身份与核心域模型分离 – 洋葱架构
我使用这个示例项目(
https://github.com/imranbaloch/ASPNETIdentityWithOnion)作为我的应用程序架构,在这个示例中,核心是从包括身份框架在内的基础设施中完全取消的.
在此示例中,作者使用适配器模式来分离核心标识类(IdentityUser,IdentityRole …),并在Core层中提供类似它们的类. 现在这个示例项目中的问题是Domain模型(Product,Images)没有与模仿Identity模型的虚拟类(AppUser,ApplicationRole,AppliationUserRoles,…)链接. 然后我修改了代码以添加对AppUser的引用 public sealed class Image : BaseEntity { public Image() { Products = new HashSet<Product>(); } public string Path { get; set; } public AppUser AppUser { get; set; } // The Added Reference ... public ICollection<Product> Products { get; set; } } 如果我将“AppUser”导航属性放在“Image”类中,则创建的数据库将具有除标识框架的默认FIVE表之外的四个新表. 我需要将这些表合并为默认表. 编辑: 这是驻留在数据层中的身份模型(我无法从核心引用). public class ApplicationIdentityUser : IdentityUser<int,ApplicationIdentityUserLogin,ApplicationIdentityUserRole,ApplicationIdentityUserClaim>,IDomainUser { public ApplicationIdentityUser() : base() { Images = new HashSet<Image>(); } public string Name { get; set; } public virtual ICollection<Image> Images { get; set; } } public class ApplicationIdentityRole : IdentityRole<int,ApplicationIdentityUserRole> { public ApplicationIdentityRole(){} public ApplicationIdentityRole(string name){Name = name;} } public class ApplicationIdentityUserRole : IdentityUserRole<int> {} public class ApplicationIdentityUserClaim : IdentityUserClaim<int>{} public class ApplicationIdentityUserLogin : IdentityUserLogin<int>{} 这也是我在OnModelCreating方法中的模型构建器: modelBuilder.Entity<Image>() .Property(e => e.Id) .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity); modelBuilder.Entity<Image>() .HasMany(e => e.Products) .WithRequired(e => e.Image) .WillCascadeOnDelete(false); modelBuilder.Entity<ApplicationIdentityUser>() .Property(e => e.Id) .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity); modelBuilder.Entity<ApplicationIdentityRole>() .Property(e => e.Id) .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity); modelBuilder.Entity<ApplicationIdentityUserClaim>() .Property(e => e.Id) .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity); 解决方法
好的,我通过执行以下操作解决了这个问题:
>在您的Core中包含对Microsoft.AspNet.Identity.Core的依赖项 我知道依赖于Microsoft.AspNet.Identity.Core听起来很奇怪,但我们只需要接口IUser,它基本上也被认为是你的应用程序的核心域模型. 这里的终极理念是完全获取Microsoft.AspNet.Identity.EntityFramework. 有兴趣的开发者可以1,所以我可以在GitHub上传一个完整的工作样本. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- asp.net-mvc – ASP.NET MVC控制器动作设计
- IIS 7中的虚拟目录ASP.NET网站的配置错误
- asp.net-mvc-3 – 如何在MVC3中键入时过滤占用
- asp.net-mvc – 如何在asp.net mvc应用程序中自动生成随机密
- asp.net Mvc4 使用ajax结合分页插件实现无刷新分页
- asp.net – Linq查询返回同一行12次
- asp.net-mvc – ASP.NET MVC:忽略基本控制器类中的自定义属
- asp.net-mvc-3 – asp.net mvc 3验证摘要不显示通过不显眼的
- 在IIS Express中无法启动asp.net核心Web应用程序
- asp.net – 在localhost中将IIS设置为Web开发服务器
- asp.net-mvc-2 – ASP.NET MVC 2 – 如何使用Dro
- asp.net-mvc-3 – MVC3客户端验证无法使用Ajax.B
- asp.net-mvc – 如何使用ASP.NET MVC的plupload包
- api – 通过msxml2.ServerXMLHTTP提供身份验证信
- 如何以编程方式单击ASP.NET网页上的按钮?
- ASP.NET JSON Web令牌“401 Unauthorized”
- asp.net-mvc – ASP.NET MVC和Unity 1.2容器问题
- asp.net-mvc-3 – MVC3:设置下拉列表选择的值
- 如何在ASP.Net webform中使用标签?
- asp.net-mvc – 在ASP.NET MVC中将多个对象暴露给