[译]用于企业应用程序的Angular2和WebApi(SPA)-第3部分-项目结构
By robot-v1.0
本文链接 https://www.kyfws.com/applications/angular-webapi-spa-for-enterprise-app-part-project-zh/
版权声明 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
- 6 分钟阅读 - 2759 个词 阅读量 0[译]用于企业应用程序的Angular2和WebApi(SPA)-第3部分-项目结构
原文地址:https://www.codeproject.com/Articles/1147130/Angular-WebApi-SPA-for-Enterprise-App-Part-Project
原文作者:tranthanhtu.vn
译文由本站 robot-v1.0 翻译
前言
This tip explains how we should structure our project folder
本技巧说明了如何构造项目文件夹
系列中的其他文章(Other Articles in the Series)
- 总览(Overview)
- 新增权限(Add new Permission)
- 项目结构(Project structure)
- 多国语言(i18n)(Multi-Languages (i18n))
- DI&IoC-为什么和为什么不?(DI & IoC - Why and Why not?)
- RESTful和Web Api(RESTful & WebApi)
- 管理应用程序生命周期(Manage Application Lifecycle)
- 构建和部署应用程序(Build & Deploy Application)
- 带有Angular 2的TinyERP的新版本(打字稿)(New version of TinyERP with Angular 2 (typescript))
- CQRS:避免企业应用程序中的性能问题(基本)(CQRS: Avoiding performance issues in enterprise app (basic))
- 多个数据存储:扩展存储库(第1部分)(Multiple data-stores: Scale your repository (Part 1))
- 多个数据存储:扩展存储库(第2部分)(Multiple data-stores: Scale your repository (Part 2))
- 使用OWIN的基本身份验证(用户名/密码)(Basic authentication (user name/ password) with OWIN)
- OWIN基于令牌的授权(Token based authorization with OWIN)
介绍(Introduction)
在本技巧中,我们学习如何为我们的应用程序组织项目.(In this tip, we learn how to organize the project for our application.)
我假设我们的应用程序具有以下功能,如下图所示:(I assume that our application has the following features as shown in the image below:)
在此图像中,我们看到:(In this image, we see that:)
- 该应用程序具有3大功能:安全性,HRM,CRM.我们通常将它们称为模块.因此,在示例应用程序中,我们有3个模块:安全模块,HRM模块和CRM模块(The application has 3 big features: Security, HRM, CRM. We usually call them as module. So in the sample application, we have 3 modules: Security module, HRM module and CRM module)
- 每个模块应相互隔离.我的意思是,在安全模块中将不会管理人员,…(Each module should be isolated from others. I mean, in Security module will not manage staff, …)
- 从1个模块开始,不应相互依赖,因为它们彼此隔离.(From 1 module, should not depend on others as they are isolated each others.)
- 我们应该使用事件进行模块通信,我的意思是,安全模块要在HRM模块中调用某些操作.安全性应触发一个事件,HRM将使用适当的事件处理程序订阅该事件.这将帮助我们降低应用程序的复杂性,并且将来更易于维护.(We should use event for module communication, I mean, Security module wants to call some action in HRM module. Security should fire an event, HRM will subscribe to that event with appropriate event handler. This will help us reduce the complexity of the application, and is easier for maintenance in the future.)
- 每个重要功能都有其自己的子功能,例如在"安全性"中,我们具有"权限",“用户角色”,“用户”," …".(Each big feature has it own sub features, such as in Security, we have Permission, User Role, User, …)
- 每个子功能(例如Permission)都可以在一个或多个页面中实现(例如,权限列表,创建权限,更新权限等).(Each sub feature (such as Permission) can be implemented in one or more pages (such as list of permissions, create permission, update permission, …))
项目结构(Project Structure)
通过上述应用程序,我们将组织如下结构:(With the above application, we will organize the structure as below:)
从上图:(From the image above:)
- 每个模块都有其自己的路线,菜单项….此信息在"(Each module will have its own route, menu items, …. this information was specified in “)**/app/modules/<模块名称>/_ share/config/module.ts(*/app/modules//_share/config/module.ts*)**"(*"*)
- 每个模块及其子功能将位于其自己的文件夹中(Each module and its sub features will be located in it own folder in)/app/modules/<模块名称>(/app/modules/).(.)
- 模块的子功能具有其自己的文件夹(例如,权限子功能的权限),并包含其详细的实现(权限列表,添加权限,更新权限).这将使我们更容易找到和修改代码.(Sub feature of module has its own folder (such as permission for permission sub feature) and contains its detailed implementation (list of permissions, add permission, update permission). This will make it easier for us to locate and modify the code.)
- 服务类,由适当的子功能(例如(Service class, used by appropriated sub feature (such as)
permissionService
)应位于”() should be located in “)_share/服务(_share/services)“在相应模块中的文件夹.(” folder in appropriated module.)permissionService
不仅在权限子功能内部使用,而且在同一模块的其他子功能(例如用户组,用户)中使用.(was not only used inside permission sub feature but also in other sub features in the same module (such as usergroup, user).) - 对于指令,由模块上的任何子功能使用.他们应该位于”(For directives, used by any sub-features on module. they should be located in “)_共享/指令(_shared/directives)“文件夹.例如,"(” folder. For example, “)
permissions
指令(显示权限列表)可以是处于权限中的用户,用户子功能.(” directive (showing the list of permissions) can be users in permission, user sub-feature.) 如果此指令位于”(If this directive was located inside “)/app/security/permission(/app/security/permission)".在用户子功能中,我们需要从权限子功能中复制或导入(这将在用户和权限子功能之间建立依赖性).这不好.(”. In user sub-feature, we need to duplicate or import from permission sub-feature (this will create dependency between user and permission sub-feature). It is not good.)
如果此指令位于"(If this directive was located inside “)/app/common/directives(/app/common/directives)".此文件夹中的指令数量很多,其中大多数仅在1个模块中使用.(”. The number of directives in this folder will be immense and most of them were used in 1 module only.)
- 在1个模块中,如果我们想通知其他模块,我们将触发事件.(Inside 1 module, we will fire event if we want to notify other modules.)
let eventManager = window.ioc.resolve("IEventManager");
eventManager.publish("<event-key>", <event argument>);
- 多国语言(i18n)资源位于"(Multi languages (i18n) resource was located in “)/app/resources/locales/<模块名称>.<语言> .json(/app/resources/locales/..json)” (如:(" (such as:)**security.en.json(security.en.json)**要么(or)security.vn.json(security.vn.json)).().) 每个模块应仅包含1种语言的文件.(Each module should have only 1 file for 1 language.)
模块的所有子功能都应使用此json文件中的文本,遵循约定" <模块的名称>.<子功能的名称>.<实现的名称>.<文本的名称>".例如, “(All sub-features of module should use texts inside this json file following the convention “...”. For example, “) security.permission.permissions.pageTitle
“将返回安全模块的权限子功能中用于权限页面标题的文本.(” will return the text used for title of permission page in permission sub-feature of security module.)
相同的规则适用于HRM,CRM模块.(The same rules were applied for HRM, CRM modules.)
许可
本文以及所有相关的源代码和文件均已获得The Code Project Open License (CPOL)的许可。
Javascript XML C# .NET IIS Visual-Studio ASP.NET DBA Dev Architect 新闻 翻译