【abp Vnext】Download and run the detailed tutorial document of abp Vnext project

Software environment : the computer needs the basic software environment node.js, npm, there are many online tutorials, please Baidu
mysql installation tutorial : Mysql installation and first login change password paste
redis installation tutorial : redis installation and client installation detailed tutorial

1. Install Visual Studio 2022

Official download of Professional 2022: https://visualstudio.microsoft.com/zh-hans/vs/
insert image description here
After the download is complete, install:
insert image description here
Click the Continue button, the following screenshot will appear
insert image description here
and then check ( ASP.NET and Web development and Visual Studio extension development )
insert image description here
insert image description here

Customize the installation location and click Install
insert image description here

insert image description here


1. Install ABP CLI scaffolding

Install ABP CLI in the command line terminal:

dotnet tool install -g Volo.Abp.Cli

If the error is as follows, it means that the local net sdk version is lower than 7.0
insert image description here
Solution
1. Download .NET 7.0 from the official website : https://dotnet.microsoft.com/en-us/download/dotnet/7.0
2. According to the computer system and version No. to download (my computer is windows10 x64 version)
insert image description here
After the installation is complete, enter the command in the terminal to verify that the version is 7, then there is no problem

dotnet --info

insert image description here
Enter the following command again in the terminal to install ABP CLI

dotnet tool install -g Volo.Abp.Cli

Screenshot after successful execution
insert image description here


2. Select the abp framework configuration

abp official website : https://abp.io/get-started
Select the corresponding configuration according to the needs (I chose the multi-layer application, mvc UI framework, mysql database, no mobile terminal)
insert image description here

then copy the command
insert image description here

Use the cmd pop-up window to enter the specified project folder
and enter the following command line

abp new Acme.BookStore -dbms MySQL --tiered --theme basic 

insert image description here

Appears as follows, indicating success
insert image description here


3. Run the abp framework

Double-click to open with vs2022

insert image description here

The default structure
insert image description here
selects Acme.BookStore.DbMigrator as the startup item
insert image description here

Modify the database configuration
Change the appsettings.json file of Acme.BookStore.AuthServer, Acme.BookStore.DbMigrator, Acme.BookStore.HttpApi.Hostto the mysql database that needs to be connected, Server is the database ip, Port is the port, Database is the database name, Uid is the database account, Pwd is the database password

insert image description here
Select EntityFrameworkCore to install the Microsoft.EntityFrameworkCore.Design package in Tools == "NuGet Package Manager ==" Package Manager Console == "Default Projectinsert image description here

insert image description here

insert image description here

insert image description here
Note:
Because the following command is entered in the cmd command window, the version number queried is 7.0.202

dotnet --version

So Microsoft.EntityFrameworkCore.Toolsthe package needs to be downgraded to version 7.0.2 (first uninstall the 7.0.4 that comes with the project, and then install 7.0.2, otherwise the project will report error 500.30), as follows
insert image description here

After the above installation is complete, enter the following command line in the console to generate the migration file

Add-Migration Init

insert image description here
Execute the migration command after running

 Update-Database

insert image description here
Then configure the startup items. In the solution Acme.BookStore, select Configure startup items
insert image description here
to select multiple startup items, then change AuthServer and Host, then click Apply, OK, and finally press Ctrl+F5 to run
insert image description here

Then the effect picture is as follows:
insert image description here


insert image description here


Step on the pit point:

1. If you need to use the Vs2022 version before installing net SDK7.0, an error will be reported when performing the migration

2. Because of the locally installed Net SDK version 7.0.202, the NuGet solution of the project Acme.BookStore.EntityFrameworkCore solution needs to be reduced to version 7.0.2, otherwise an error 500.30 will be reported when running the project

3. Official document: Introduce the role of directory structure


Projects are organized in src and test folders. The src folder contains the actual application, which is layered based on the previously mentioned DDD principles. The following diagram shows the layers of the solution and the dependencies of the projects:

insert image description here

The following describes the projects and dependencies in the solution

.Domain.Shared Items

Projects contain constants, enums and other objects that are actually part of the domain layer, but are used by all layers/projects in the solution.

For example the BookType enum and the BookConsts class (perhaps
a constant field used by the Book entity, like MaxNameLength) are suitable for this project.

This project does not depend on other projects in the solution. Other projects depend on this project directly or indirectly

.Domain project

The domain layer of the solution. It mainly contains entities, collection roots, domain services, value types, storage interfaces and other domain objects of the solution.

For example, the Book entity and the IBookRepository interface are suitable for this project.

It depends on the .Domain.Shared project, because some of its constants, enumerations and definitions of other objects will be used in the project. The .Application.Contracts
project mainly includes application service interfaces and data transfer objects (DTO) of the application layer. It uses It is used to separate the interface and implementation of the application layer.
In this way, the interface project can be shared with the client as a contract package.

For example, the IBookAppService interface and the BookCreationDto class are suitable for this project.

It relies on .Domain.Shared because it may use constants, enums and other shared objects in application interfaces and DTOs.

.Application project

The project contains the application service interface implementation of the .Application.Contracts project.

For example the BookAppService class would fit in this project.

It depends on the .Application.Contracts project because it needs to implement interfaces and use DTO. It depends on the .Domain
project because it needs to use domain objects (entities, storage interfaces, etc.) to execute application logic. The .EntityFrameworkCore project is integrated with EF
Core project. It defines the DbContext and implements the repository interface defined in the .Domain project.

It depends on the .Domain project because it needs to reference entities and storage interfaces. This project is only available if you use EF Core as the database provider. If you choose
another database provider, the name of the project will change

.EntityFrameworkCore.DbMigrations project

Contains EF Core database migrations for the solution. It has a separate DbContext dedicated to managing migrations.

ABP is a modular framework, the ideal design is to let each module have its own DbContext class. At this time, the DbContext for migration will play a role.
It will unify all DbContext configurations into a single model to maintain a single database schema.
For more advanced scenarios, a program can have multiple databases (each with one or more module tables) and multiple migration DbContexts (each maintaining a different database schema)

Note that the migration DbContext is only used for database migrations, not at runtime.

It relies on the .EntityFrameworkCore project because it reuses the application's DbContext configuration.
This project is only available if you are using EF Core as your database provider. See the Entity Framework Core Migration Guide for details on this project.

.DbMigrator project

This is a console application that simplifies performing database migrations in development and production environments. When you use it;

Create database if necessary (when there is no database). Apply unmigrated database migrations. Initialize seed data (when you need it). This project has its own appsettings.json
file. So if you want to change the database connection string, please remember to also Change this file.

It is important to initialize the seed data, ABP has a modular seed data infrastructure. For more information on seed data, please refer to the documentation.

While creating databases and applying migrations seems to be useful only for relational databases, this project is generated even if you choose a NoSQL database provider such as MongoDB. At
this point, it provides the necessary initial data for the application.

It depends on the .EntityFrameworkCore.DbMigrations project (for EF Core) because it needs access to the migration files. It depends on
the .Application.Contracts project because it needs the access permissions definition to give all permissions to the admin user when initializing the seed data.

.HttpApi project

Used to define API controllers.

Most of the time, you don't need to manually define API controllers, because ABP's dynamic API feature will automatically create API controllers according to your application layer.
However, if you need to write API controllers, then it is the most suitable place.

It depends on the .Application.Contracts project, because it needs to inject the application service interface. The .HttpApi.Client project
defines the C# client proxy to use the solution's HTTP API project. The above edits can be shared with third-party clients, making it easy to use in DotNet applications use your HTTP
API (other types of applications can use your API manually or using their platform's tools).

ABP has dynamic C# API client function, so in most cases you don't need to manually create C# client proxy.

The .HttpApi.Client.ConsoleTestApp project is a console application for demonstrating client proxy usage.

It depends on the .Application.Contracts project, because it needs to use the application service interface and DTO.
If you don't need to create a dynamic C# client proxy for the API, you can delete this project and dependencies

.Web project

Contains the user interface (UI) of the application. If using ASP.NET Core MVC UI,
it includes Razor pages, javascript files, style files, images, etc...

Contains the main appsettings.json configuration file of the application, which is used to configure the database connection string and other configurations of the application

Depends on the .HttpApi project, because the UI layer needs to use the solution's API and application service interface. If you look at the .Web.csproj source code, you will see
references to the .Application and .EntityFrameworkCore.DbMigrations projects.

These references are actually not needed when writing the UI layer. Because the UI layer usually does not depend on the implementation of EF Core or the application layer.
This startup template is ready for layered deployment, and the API layer is hosted on a different server from the UI layer. middle.

But if you don't select the --tiered option, the .Web project will have these references to be able to host the Web, Api and Application tiers in a single application site.

You can use domain entities and repositories in the presentation layer, but according to the theory of DDD, this is considered a bad practice.

Test project

The solution has multiple test projects, one for each layer:

.Domain.Tests is used to test domain layer. .Application.Tests is used to test application layer.
.EntityFrameworkCore.Tests is used to test EF Core configuration and custom storage. .Web.Tests
is used to test UI (for ASP.NET Core MVC UI). .TestBase The base (shared) project for all test projects. Also,
.HttpApi.Client.ConsoleTestApp
is a console application (not an automated test project) which is used to demonstrate the usage of the HTTP API in .Net applications .

The test project is used for integration testing:

It is fully integrated into the ABP framework and all services of the application. If the database provider is EF
Core, the test project will use the SQLite in-memory database, if it is MongoDB, it will use the Mongo2Go library.
Authorization is disabled, and any application service can be used in the test
You can still write unit tests, but it's harder to write (because you need to prepare mock/fake objects), but it runs faster (because you only test a single class and skip all initialization processes) .

Guess you like

Origin blog.csdn.net/weixin_43861689/article/details/129581932