洋葱架构身份框架 [英] Onion Architecture Identity Framework

查看:158
本文介绍了洋葱架构身份框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在关注洋葱体系结构.在这种情况下,我正在使用ASP.NET Identity Framework.

I am following Onion Architecture. And in that I am using ASP.NET Identity Framework.

这是我的项目结构:

1-Core
     - Domain Classes //It contains my T4 template classes
          -- AppUser  //It is Identity User.  
     - Repository Interfaces
     - Service Interfaces
2-Infrastructure
     - Data //It contains my edmx file, I am using Db First approach.
     - Dependency Injection
     - Repository Interfaces Implementation
     - Service Interfaces Implementation
3-WebApi
     - Web Api Project
4-WebClient
     - My AngularJs App
5-Test
     - Test Project

我已复制ASP.NET标识表的脚本并在我的SQL Server上执行.哪个为我创建了身份表.

I have copied the scripts of the ASP.NET Identity tables and executed on my SQL Server. Which created Identity Tables for me.

在我的Infrastructure.Data项目中,我创建了一个Edmx File并在其中插入了身份表.然后将T4 template移到Core.Domain,在这里为AppUser和其他Identity表创建了Partial Class.

In my Infrastructure.Data project, I created an Edmx File and inserted Identity tables in it. Then I moved my T4 template to Core.Domain, here I created Partial Class for my AppUser and other Identity tables.

// This make my Core.Domain project dependent on `Microsoft.AspNet.Identity`
// Which is a violation. 
public partial class AppUser : IdentityUser 
{
    //My Custom Properties
}

现在,我对Core中的AppUser类感到困惑.根据洋葱架构标准,整个层不应依赖于任何外部库.但是这里我使用"Microsoft.AspNet.Identity"来使我的用户成为身份用户.有什么解决办法吗?

Now I have confusion about my AppUser Class which is in Core. According to the Onion Architecture standards, This whole layer should not a be dependent on any external library. But here I am using 'Microsoft.AspNet.Identity' in order to make my user as Identity User. Is there any solution for that?

推荐答案

从IdentityUser派生的AppUser问题现在是您的核心项目依赖于它为Asp.Net设计的框架,在那里您的核心项目可能会产生偏差.您是正确的,即核心(即中央)项目应该与平台无关.

The problem with AppUser deriving from IdentityUser is now your core project is dependant on a framework which it designed for Asp.Net, there your core project can become biased. You are correct that the core (i.e. central) project should be platform independent.

如果要使用IdentityUser,可以在WebClient/WebApi项目中定义一个User实体,该实体继承自IdentityUser,并将其保留在这些表示层中,而与核心区分开.

If you want to use IdentityUser you could define a User entity within your WebClient/WebApi projects which inherit from IdentityUser and keep them within these presentation layers, away from the core.

要将您的演示文稿用户实体传达到核心,您可以将属性手动映射到核心AppUser或使用诸如 AutoMapper

To convey your presentation user entity to the core you can manually map the properties to your core AppUser or use a mapping tool like AutoMapper

修改

包含的图:

1-Core
    - Domain Classes 
        -- AppUser    
    - Repository Interfaces
    - Service Interfaces
2-Infrastructure
    - Data //It contains my edmx file, I am using Db First approach.
    - Dependency Injection
    - Repository Interfaces Implementation
    - Service Interfaces Implementation
3-WebApi
    - Web Api Project
        - Models
            ApiUser : *(Inherits Api Identity framework)*
4-WebClient
    - My AngularJs App
        - Models
            WebUser : *(Inherits IdentityUser)*
5-Test
    - Test Project

这篇关于洋葱架构身份框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆