且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

我需要构建新的ASP MVC应用程序帮助

更新时间:2022-12-21 12:56:35

这就是我组织了我最近的项目之一:

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 the ApplicationUser class that inherits from IdentityUser 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 references Microsoft.AspNet.Identity.Core and Microsoft.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.