草叶睡蜢

导航

3 Implementation: The Big Picture 实现:蓝图

三、Implementation: The Big Picture 实现:蓝图

3.1 Layering of a .NET Solution .Net解决方案的分层

The picture below shows a Visual Studio Solution created using the ABP's application startup template:

使用ABP的应用程序启动模板创建的Visual Studio解决方案,如下图所示:
image
The solution name is IssueTracking and it consists of multiple projects. The solution is layered by considering DDD principles as well as development and deployment practicals. The sub sections below explains the projects in the solution;

该解决方案的名称叫IssueTracking,它由多个项目组成。该解决方案分层时充分考虑DDD原则以及开发和部署的实际情况。下面的小节对解决方案中的各个项目进行解释。

Your solution structure may be slightly different if you choose a different UI or Database provider. However, the Domain and Application layers will be same and this is the essential point for the DDD perspective. See the Application Startup Template document if you want to know more about the solution structure.

如果你选择不同的UI或数据库,你的解决方案结构可能会略有不同。然而,领域层和应用层是一样的,并且这是DDD的关键点。如果你想了解更多关于解决方案结构的信息,请参阅应用程序启动模板的说明文档。

3.1.1 The Domain Layer 领域层

The Domain Layer is splitted into two projects;

领域层分为两个项目:

  • IssueTracking.Domain is the essential domain layer that contains all the building blocks (entities, value objects,domain services, specifications, repository interfaces, etc.)introduced before.

  • IssueTracking.Domain是领域层,包含了之前介绍的所有构件(实体、值对象、领域服务、规范、资源库接口等)。

  • IssueTracking.Domain.Shared is a thin project that contains some types those belong to the Domain Layer,but shared with all other layers. For example, it may contain some constants and enums related to the Domain Objects but need to be reused by other layers.

  • IssueTracking.Domain.Shared是一个单薄的项目,它包含一些领域层的类型,并与所有其他层共享。例如,它可能包含一些与领域对象相关的常量和枚举,需要被其他层重用。

3.1.2 The Application Layer 应用层

The Application Layer is also splitted into two projects;
应用层也分为两个项目:

  • IssueTracking.Application.Contracts contains the application service interfaces and the DTOs used by these interfaces. This project can be shared by the client applications (including the UI).
  • IssueTracking.Application.Contracts包含应用服务的接口和这些接口所使用的DTO。这个项目可以被客户端应用程序(包括UI)使用。
  • IssueTracking.Application is the essential application layer that implements the interfaces defined in the Contracts project.
  • IssueTracking.Application 是重要的应用层,它实现了IssueTracking.Application.Contracts项目中定义的接口。

3.1.3 The Presentation Layer 展现层

  • IssueTracking.Web is an ASP.NET Core MVC / Razor Pages application for this example. This is the only executable application that serves the application and the APIs.
  • IssueTracking.Web是本例的ASP.NET Core MVC / Razor Pages应用程序。这是唯一的可执行应用程序,为应用程序和API服务。
    ABP Framework also supports different kind of UI frameworks including Angular and Blazor. In these cases, the IssueTracking.Web doesn't exist in the solution. Instead, an IssueTracking.HttpApi.Host application will be in the solution to serve the HTTP APIs as a standalone endpoint to be consumed by the UI applications via HTTP API calls.
    ABP框架也支持不同类型的UI框架,包括Angular和Blazor。在这种情况下,解决方案中就不存在IssueTracking.Web项目。反而,IssueTracking.HttpApi.Host应用程序将在解决方案中作为一个独立的终端为HTTP API提供服务,通过HTTP API调用被UI应用程序所使用。

3.1.4 The Remote Service Layer 远程服务层

  • IssueTracking.HttpApi project contains HTTP APIs defined by the solution. It typically contains MVC Controllers and related models, if available. So, you write your HTTP APIs in this project.
  • IssueTracking.HttpApi项目包含解决方案中定义的HTTP APIs。它通常包含MVC控制器和相关模型(如果有的话)。所以,你在这个项目中编写你的HTTP APIs。
    Most of the time, API Controllers are just wrappers around the Application Services to expose them to the remote clients. Since ABP Framework's Automatic API Controller System automatically configures and exposes your Application Services as API Controllers, you typically don't create Controllers in this project. However, the startup solution includes it for the cases you need to manually create API controllers.
    大多数时候,API控制器只是应用服务的包装,将它们暴露给远程客户端。由于ABP框架的自动API控制器系统可以自动配置并将你的应用服务作为API控制器暴露出来,你通常不用在这个项目中创建控制器。然而,启动方案包括它是为了满足你需要手动创建API控制器的情况。
  • IssueTracking.HttpApi.Client project is useful when you have a C# application that needs to consume your HTTP APIs. Once the client application references this project, it can directly inject & use the Application Services. This is possible by the help of the ABP Framework's Dynamic C# Client API Proxies System.
  • IssueTracking.HttpApi.Client 当你有一个C#应用程序需要使用你的HTTP APIs时,IssueTracking.HttpApi.Client项目是非常有用的。一旦客户端应用程序引用了这个项目,它就可以直接注入和使用这些应用服务。通过ABP框架的C#客户端API动态代理系统的帮助这是可能的。
    There is a Console Application in the test folder of the solution,named IssueTracking.HttpApi.Client.ConsoleTestApp. It simply uses the IssueTracking.HttpApi.Client project to consume the APIs exposed by the application. It is just a demo application and you can safely delete it. You can even delete the IssueTracking.HttpApi.Client project if you think that you don't need to them.
    在解决方案的test文件夹中有一个控制台应用程序,叫IssueTracking.HttpApi.Client.ConsoleTestApp。它只是使用应用程序IssueTracking.HttpApi.Client项目所暴露的API。它只是一个演示应用程序,你可以安全地删除它。如果你认为不需要,你甚至可以删除IssueTracking.HttpApi.Client项目。

3.1.5 The Infrastructure Layer 基础设施层

In a DDD implementation, you may have a single Infrastructure project to implement all the abstractions and integrations, or you may have different projects for each dependency.
在DDD的实施中,你可能有一个单独的基础设施项目来实现所有的抽象和集成,或者你可能为每个依赖创建不同的项目。
We suggest a balanced approach; Create separate projects for main infrastructure dependencies (like Entity Framework Core) and a common infrastructure project for other infrastructure.
我们建议采取一种平衡的方法;为主要的基础设施依赖(如Entity Framework Core)创建单独的项目,为其他基础设施创建一个公共的基础设施项目。
ABP's startup solution has two projects for the Entity Framework Core integration;
ABP的启动方案有两个项目用于Entity Framework Core的集成:

  • IssueTracking.EntityFrameworkCore is the essential integration package for the EF Core. Your application's DbContext, database mappings, mplementations of the repositories and other EF Core related stuff are located here.
  • IssueTracking.EntityFrameworkCore 是EF Core的基本集成包。应用程序的DbContext、数据库映射、资源库的实现和其他EF Core相关的东西都放在这里。
  • IssueTracking.EntityFrameworkCore.DbMigrations is a special project to manage the Code First database migrations. There is a separate DbContext in this project to track the migrations. You typically don't touch this project much except you need to create a new database migration or add an application module that has some database tables and naturally requires to create a new database migration.
  • IssueTracking.EntityFrameworkCore.DbMigrations 是一个特殊的项目,用于管理Code First模式的数据库的迁移。在这个项目中,有一个单独的DbContext来跟踪迁移。除非你需要创建一个新的数据库迁移,或者添加一个已经存在数据库表的应用程序模块,这当然需要创建一个新的数据库迁移,否则你通常不要动这个项目。
    You may wonder why there are two projects for the EF Core. It is mostly related to modularity. Each module has its own independent DbContext and your application has also one DbContext. DbMigrations project contains a union of the modules to track and apply a single migration path. While most of the time you don't need to know it, you can see the EF Core migrations document for more information.
    你可能想知道为什么EF Core有两个项目。这主要是与模块化有关。每个模块都有自己单独的DbContext,你的应用程序也有一个DbContext。DbMigrations项目包含了各模块的联合,以跟踪和运用单一的迁移路径。虽然大多数时候你不需要了解它,但你可以查看EF Core迁移文档以了解更多信息。

3.1.6 Other Projects 其它项目

There is one more project, IssueTracking.DbMigrator, that is a simple Console Application that migrates the database schema and seeds the initial data when you execute it. It is a useful utility application that you can use it in development as well as in production environment.
还有一个项目,IssueTracking.DbMigrator,它是一个简单的控制台应用程序,当你执行它时,它会同步数据库结构并产生初始化数据。这是一个有用的工具程序,你可以在开发环境和生产环境中使用它。

posted on 2021-10-16 11:51  草叶睡蜢  阅读(118)  评论(0编辑  收藏  举报