Generates a new solution based on the ABP [startup templates](Startup-Templates/Index.md).
生成基于ABP[启动模板](Startup-Templates/Index.md)的新解决方案.
Basic usage:
基本用法:
````bash
abp new <solution-name> [options]
abp new <解决方案名称> [options]
````
Example:
示例:
````bash
abp new Acme.BookStore
````
* Acme.BookStore is the solution name here.
* Common convention is to name a solution is like *YourCompany.YourProject*. However, you can use different naming like *YourProject* (single level namespacing) or *YourCompany.YourProduct.YourModule* (three levels namespacing).
* `--tiered`: Creates a tiered solution where Web and Http API layers are physically separated. If not specified, it creates a layered solution which is less complex and suitable for most scenarios.
* `mvc-module`: ASP.NET Core [MVC module template](Startup-Templates/Mvc-Module.md). Additional options:
* `--no-ui`: Specifies to not include the UI. This makes possible to create service-only modules (a.k.a. microservices - without UI).
* `--output-folder`or `-o`: Specifies the output folder. Default value is the current directory.
Adds a multi-package module to a solution by finding all packages of the module, finding related projects in the solution and adding each package to the corresponding project in the solution.
> A business module generally consists of several packages (because of layering, different database providr options or other reasons). Using `add-module` command dramatically simplifies adding a module to a solution. However, each module may require some additional configurations which is generally indicated in the documentation of the related module.
* This example add the Volo.Blogging module to the solution.
* 示例中将Volo.Blogging模块添加到解决方案中.
#### Options
* `--solution`or `-s`: Specifies the solution (.sln) file path. If not specified, CLI tries to find a .sln file in the current directory.
* `--skip-db-migrations`: For EF Core database provider, it automatically adds a new code first migration (`Add-Migration`) and updates the database (`Update-Database`) if necessary. Specify this option to skip this operation.
Updating all ABP related packages can be tedious since there are many packages of the framework and modules. This command automatically updates all ABP related packages in a solution or project to the latest versions.
This template provides a layered (or tiered, based on the preference) application structure based on the [Domain Driven Design](../Domain-Driven-Design.md) (DDD) practices.
You can use the [ABP CLI](../CLI.md) to create a new project using this startup template. Alternatively, you can directly create & download from the [Get Started](https://abp.io/get-started) page. CLI approach is used here.
* `Acme.BookStore`is the solution name, like *YourCompany.YourProduct*. See the [CLI document](../CLI.md) for different naming styles.
* This example specified the template name (`-t` or `--template` option). However, `mvc` is the default template and used even if you don't specify it.
This template supports the following database providers:
`MVC`模板支持以下数据库提供程序:
- `ef`: Entity Framework Core (default)
- `ef`: Entity Framework Core (默认)
- `mongodb`: MongoDB
Use the `-d` (or `--database-provider`) to specify the database provider:
使用 `-d` (或 `--database-provider`) 指定数据库提供程序:
````bash
abp new Acme.BookStore -t mvc -d mongodb
````
### Create a Tiered Solution
### 创建分层解决方案
`--tiered` option is used to create a tiered solution where Web and Http API layers are physically separated. If not specified, it creates a layered solution which is less complex and suitable for most scenarios.
Projects are organized in `src` and `test` folders. `src` folder contains the actual application which is layered based on [DDD](../Domain-Driven-Design.md) principles as mentioned before.
**TODO: Add a graphic to illustrate dependencies between projects.**
**TODO: 添加一些图来说明项目之间的依赖关系.**
------------------
Each section below will explain the related project.
下面介绍解决方案中的项目.
#### .Domain Project
#### .Domain 项目
This is the domain layer of the solution. It mainly contains [entities, aggregate roots](../Entities.md), [domain services](../Domain-Services.md), [value types](../Value-Types.md), [repository interfaces](../Repositories.md) and other domain objects of the solution.
This project contains constants, enums and other objects these are actually a part of the domain layer, but needed to be used by all layers/projects in the solution.
A `BookType` enum and a `BookConts` class (which may have some constant fields for the `Book` entity, like `MaxNameLength`) are good candidates for this project.
This project has no dependency to other projects in the solution.
该项目不会依赖解决方案中的其他项目.
#### .Application.Contracts Project
#### .Application.Contracts 项目
This project mainly contains [application service](../Application-Services.md) **interfaces** and [Data Transfer Objects](../Data-Transfer-Objects.md) (DTO) of the application layer. It does exists to separate interface & implementation of the application layer. In this way, the interface project can be shared to the clients as a contract package.
This project contains the [application service](../Application-Services.md) implementations of the interfaces defined in the `.Application.Contracts` project.
* Depends on the `.Domain` project to be able to reference to entities and repository interfaces.
* 它依赖 `.Domain` 项目,因为它需要引用实体和仓储接口.
> This project is available only if you are using EF Core as the database provider.
> 只有在你使用了EF Core做为数据库提供程序时,此项目才会可用.
#### .EntityFrameworkCore.DbMigrations Project
#### .EntityFrameworkCore.DbMigrations 项目
Contains EF Cor database migrations for the solution. It has a separated `DbContext` to dedicated to manage migrations.
包含解决方案的EF Core数据库迁移. 它有独立的 `DbContext` 来专门管理迁移.
ABP is a modular framework and with an ideal design, each module has its own `DbContext` class. This is where the migration `DbContext` comes into play and unifies all `DbContext` configurations into a single model to maintain a single database schema.
Especially, seeding initial data is important at this point. ABP has a modular data seed infrastructure. See [its documentation](../Data-Seeding.md) for more about the data seeding.
While creating database & applying migrations seems only necessary for relational databases, this projects comes even if you choose a NoSQL database provider (like MongoDB). In that case, it still seeds initial data which is necessary for the application.
* Depends on the `.EntityFrameworkCore.DbMigrations` project (for EF Core) since it needs to access to the migrations.
* Depends on the `.Application.Contracts` project to be able to access permission definitions, because initial data seeder grants permissions for the admin user.
This project is used to define your API Controllers.
用于定义API控制器.
Most of time you don't need to manually define API Controllers since ABP's [Auto API Controllers](../AspNetCore/Auto-API-Controllers.md) feature creates them automagically based on your application layer. However, in case of you need to write API controllers, this is the best place to do it.
* Depends on the `.Application.Contracts` project to be able to inject the application service interfaces.
* 它依赖 `.Application.Contracts` 项目,因为它需要注入应用服务接口.
#### .HttpApi.Client Project
#### .HttpApi.Client 项目
This is a project that defines C# client proxies to use the HTTP APIs of the solution. You can share this library to 3rd-party clients, so they can easily consume your HTTP APIs in their Dotnet applications.
Most of time you don't need to manually create C# client proxies, thanks to ABP's [Cynamic C# API Clients](../AspNetCore/Dynamic-CSharp-API-Clients.md) feature.
ABP有[动态 C# API 客户端](../AspNetCore/Dynamic-CSharp-API-Clients.md)功能,所以大多数情况下你不需要手动的创建C#客户端代理.
* Depends on the `.Application.Contracts` project to be able to share the same application service interfaces and DTOs with the remote service.
* Depends on the `.HttpApi` since UI layer needs to use APIs and application service interfaces of the solution.
* 依赖 `.HttpApi` 项目,因为UI层需要使用解决方案的API和应用服务接口.
> If you check the source code of the `.Web.csproj` file, you will see the references to the `.Application` and the `.EntityFrameworkCore.DbMigrations` projects.
> These references are actually not needed on development, because UI layer normally doesn't depend on the EF Core or the Application implementation. This startup templates are ready for the tiered deployment, where API layer is hosted in a separate server than the UI layer.
> However, if you don't choose the `--tiered` option, these references will be in the .Web project to be able to host the Web, API and application layers in a single application endpoint.
In addition, `.HttpApi.Client.ConsoleTestApp` is a console application (not an automated test project) which demonstrate the usage of HTTP APIs from a Dotnet application.