我需要构建新的ASP MVC应用程序帮助
我要开始一个新的MVC项目和往常一样我对ASP的身份问题:)(不知道在哪里把那个XX的东西)
我计划组织这样的解决方案:
I need to start a new mvc project and as always I have issues about asp identity :) (never know where to put that d**n thing)
I plan to organize solution like this:
ProjectWebUI - mvc app with asp identity framework (made from internet template with authentication)
ProjectDataAccessLayer - with repository classes that use `dapper` as database access technology
ProjectWebAPI - web service
不过,我有一个小confustion并开始之前我的编码需要从别人更多的经验
意见(如到现在为止我所有的项目都只有一个项目在它的数据访问)
1.这是好主意,有使用标准实体框架进行数据访问和使用短小精悍在单独的程序集中其他数据访问WebUI中项目中的ASP身份?
2.如果ASP身份是Web UI的项目中,我将有一些问题,收到对项目的WebAPI验证访问?
But I have a little confustion and before start coding I need advice from someone more
experienced (as until now all my projects were just one project with data access in it)
1. Is it good idea to have asp identity inside WebUI project that use standard Entity Framework for data access and use dapper for other data access in separate assembly?
2. If asp identity is inside web ui project will I have some issues to receive authenticated access to WebAPI project?
这就是我组织了我最近的项目之一:
That's how I organized one of my recent projects:
-
通用
- 这是在解决方案中的一个核心项目。它包含了所有的域实体与ApplicationUser
类,从IdentityUser
从ASP.NET身份框架类继承一起。通常这个类是在一个新的ASP.NET MVC项目模板中找到;我决定把它放到核心库,因为它重新presents可能需要更高层次和抽象级别常见的实体。正因为如此,通用
引用Microsoft.AspNet.Identity.Core
和Microsoft.AspNet。 Identity.EntityFramework
组件。
Common
— this is a core project in the solution. It contains all the domain entities along with theApplicationUser
class that inherits fromIdentityUser
class from ASP.NET Identity Framework. Normally this class is found in a new ASP.NET MVC project template; I decided to put it into the core library because it represents a common entity that may be required for higher layers and levels of abstraction. Because of this,Common
referencesMicrosoft.AspNet.Identity.Core
andMicrosoft.AspNet.Identity.EntityFramework
assemblies.
数据访问
- 这个项目引用通用
库,包含实体Franework DatabaseContext
以及一些仓库。我用code第一种方法,我的 DatabaseContext
是 IdentityDbContext&LT继承; ApplicationUser>
。所以,它给我的表一个不错的数据库结构为用户
和角色
和其他ASP.NET身份的东西以及这再次present从通用
项目我自定义的业务实体,这样我就可以很容易地识别物体连接我的自定义实体。
DataAccess
— this project references Common
library and contains Entity Franework DatabaseContext
as well as some repositories. I use Code First approach and my DatabaseContext
is inherited from IdentityDbContext<ApplicationUser>
. So it gives me a nice database structure with tables for Users
and Roles
and other ASP.NET Identity stuff as well as tables that represent my custom business entities from the Common
project, so I can easily connect my custom entities with Identity objects.
的WebAPI
- 这是一个使用 REST
服务数据访问
和通用
库。所有的授权和认证工作正在使用令牌认证在这里完成的。
WebApi
— this is a REST
service that uses DataAccess
and Common
libraries. All the authorization and authentication job is done here using token authentication.
网站
- 这仅仅是我的 REST
服务的Web客户端
Web
— this is just a web client for my REST
service.
因此,要回答你的问题:你可以保留,如果它真的很小,易于管理单个项目中的ASP.NET身份类和Entity Framework数据库环境;否则,这将是更好地从默认的项目模板一步之遥,介绍层每个主要应用模块。
So, to answer your question: you can keep your ASP.NET Identity classes and Entity Framework database context inside a single project if it is really small and easy to manage; otherwise, it would be better to step away from the default project template and introduce layers for each major application module.