一、简介:

Abp VNext 是继Abp后完全基于Asp.net Core开发的开源项目,完全模块化组件化;

比Abp更简洁更轻盈,支出多租户,聚焦微服务;

已稳定,可用于生产;

基于.Net 5.0目标框架;

二、基础信息:

1、官方网站: ABP Framework - Open Source Web Application Framework

2、官方文档:Documentation Center | ABP.IO

3、官方模板生成下载地址:Get Started | ABP.IO

4、源代码地址:GitHub - abpframework/abp: Open Source Web Application Framework for ASP.NET Core

5、基于Abp Vnext 开发的开源项目地址(若干现成可用项目):EasyAbp Team · GitHub

三、创建项目:

方法1(推荐):直接去官方模板下载自己的项目

方法2:通过abp cli 脚手架 创建项目

1、安装工具: dotnet tool install -g Volo.Abp.Cli

2、生成项目:abp new AoRuiDe.GasMonitoring

方法3:纯手动创建项目

四、项目结构:

	│   .gitattributes
	│   .gitignore:配置代码管理需要忽略的文件
	│   common.props
	│   AoRuiDe.GasMonitoring.sln
	│   AoRuiDe.GasMonitoring.sln.DotSettings
	├───src
	│   ├───AoRuiDe.GasMonitoring.Application:---------------------应用层 依赖 Domain  Application.Contracts
	│   ├───AoRuiDe.GasMonitoring.Application.Contracts:-----------应用层接口相关 DTO  依赖:Domain.Shared
	│   ├───AoRuiDe.GasMonitoring.DbMigrator:----------------------控制台程序 单独的数据库配置 依赖 EntityFrameworkCore.DbMigrations Application.Contracts
	│   ├───AoRuiDe.GasMonitoring.Domain:--------------------------实体, 集合根, 领域服务, 值类型, 仓储接口 和解决方案的其他领域对象.实体和 Repository 接口 依赖Domain.Shared
	│   ├───AoRuiDe.GasMonitoring.Domain.Shared: ------------------存放常量 资源 枚举 等...
	│   ├───AoRuiDe.GasMonitoring.EntityFrameworkCore:-------------集成EF Core的项目. 定义DbContext 和实现Domain 项目中定义的仓储接口 依赖Domain
	│   ├───AoRuiDe.GasMonitoring.EntityFrameworkCore.DbMigrations:用于CodeFirst 生成数据库迁移文件 依赖 .EntityFrameworkCore 项目
	│   ├───AoRuiDe.GasMonitoring.HttpApi:-------------------------API控制器 依赖 Application.Contracts  注入
	│   ├───AoRuiDe.GasMonitoring.HttpApi.Client:------------------客户端代理使用的HTTP API项目  依赖 Application.Contracts
    │   ├───AoRuiDe.GasMonitoring.HttpApi.Host:---------------------【Web和API分离】API统一接口项目(官方模板项目生成工具中 勾选Tiered选项才有此项目)
    │   ├───AoRuiDe.GasMonitoring.HttpApi.IdentityServer:-----------【单点登录】统一登录授权项目(官方模板项目生成工具中 勾选Tiered选项才有此项目)
	│   └───AoRuiDe.GasMonitoring.Web: -----------------------------MVC界面  依赖 HttpApi
	└───test:测试项目
	    ├───AoRuiDe.GasMonitoring.Application.Tests:-----------应用测试 
	    ├───AoRuiDe.GasMonitoring.Domain.Tests:----------------领域测试
	    ├───AoRuiDe.GasMonitoring.EntityFrameworkCore.Tests
	    ├───AoRuiDe.GasMonitoring.HttpApi.Client.ConsoleTestApp
	    ├───AoRuiDe.GasMonitoring.TestBase
    └───AoRuiDe.GasMonitoring.Web.Tests

五、准备项目运行所需数据库(默认的MsSql):

0、采用 Visual Studio 2019  自带的 SQL Server Express LocalD 版本

1、VS2019 打开左边 Sql对象资源管理 -> 添加新的数据库 NewDataBase

默认采用windows登录的  不需要账号密码  程序中配置地址和数据库名字就可以访问

2、配置数据库连接: AoRuiDe.GasMonitoring.DbMigrator   AoRuiDe.GasMonitoring.Web 

【web Api分离模式:AoRuiDe.GasMonitoring.IdentityServer   AoRuiDe.GasMonitoring.HttpApi.Host 】

//appsetings.json   配置数据库连接 使用VS2019自带的数据库(默认windows账户 无需账号密码)
//如果有现成的MSSql数据 

"ConnectionStrings": {

    "Default": "Server=(LocalDb)\\ProjectsV13;Database=NewDataBase;Trusted_Connection=True;MultipleActiveResultSets=true"

  },

五、准备项目运行所需数据库(MySql):

0、自己去MySql官网下载安装免费的MySql社区版本;

1、AoRuiDe.GasMonitoring.EntityFrameworkCore 项目 Nuget卸载  Volo.Abp.EntityFrameworkCore.SqlServer

2、AoRuiDe.GasMonitoring.EntityFrameworkCore 项目 Nuget安装 Volo.Abp.EntityFrameworkCore.MySQL

3、替换AoRuiDe.GasMonitoring.EntityFrameworkCore 项目中的数据库使用申明

//AoRuiDe.GasMonitoring.EntityFrameworkCore\EntityFrameworkCore\GasMonitoringEntityFrameworkCoreModule.cs

using Volo.Abp.EntityFrameworkCore.MySQL;

[DependsOn(        
        //typeof(AbpEntityFrameworkCoreSqlServerModule),
        typeof(AbpEntityFrameworkCoreMySQLModule) )]
Configure<AbpDbContextOptions>(options =>
            {
                /* The main point to change your DBMS.
                 * See also GasMonitoringMigrationsDbContextFactory for EF Core tooling. */
                //options.UseSqlServer();
                options.UseMySQL();
            });

4、替换 AoRuiDe.GasMonitoring.EntityFrameworkCore.DbMigrations 项目中的数据库使用申明

//AoRuiDe.GasMonitoring.EntityFrameworkCore.DbMigrations\EntityFrameworkCore\GasMonitoringMigrationsDbContextFactory.cs
public GasMonitoringMigrationsDbContext CreateDbContext(string[] args)
        {
            
            var builder = new DbContextOptionsBuilder<GasMonitoringMigrationsDbContext>()
                //.UseSqlServer(configuration.GetConnectionString("Default"));
                .UseMySql(configuration.GetConnectionString("Default"), ServerVersion.AutoDetect(configuration.GetConnectionString("Default")));
            
        }

5、配置数据库连接: AoRuiDe.GasMonitoring.DbMigrator   AoRuiDe.GasMonitoring.Web 

【web Api分离模式:AoRuiDe.GasMonitoring.IdentityServer   AoRuiDe.GasMonitoring.HttpApi.Host 】

  "ConnectionStrings": {
    "Default": "server=localhost;database=abp_vnext_test;user=root;password=520xxx;"
  },

六、导入项目运行所需数据库表结构到数据库:

1、安装当前项目对应的SDK版本:Download .NET 5.0 (Linux, macOS, and Windows) (microsoft.com)

安装之后 才支持控制台进入到对应的项目目录,通过dotnet run 执行对应的程序。

1、AoRuiDe.GasMonitoring.EntityFrameworkCore.DbMigrations 项目安装 Nuget 包:Microsoft.EntityFrameworkCore.Design 

2、清空 AoRuiDe.GasMonitoring.EntityFrameworkCore.DbMigrations 项目目录下Migrations文件夹中已经生成的数据库迁移文件

3、打开控制台管理器:工具->nuget包管理器->程序包管理器控制台

4、安装 dotnet ef 工具:dotnet tool install --global dotnet-ef 

5、安装必备插件:dotnet add package Microsoft.EntityFrameworkCore.Design

6、进入迁移文件项目目录:cd  src\AoRuiDe.GasMonitoring.EntityFrameworkCore.DbMigrations

7、生成数据库迁移文件:dotnet ef migrations add  Initial_Migrations_01 

注1:如果已经安装且任然提示缺少Microsoft.EntityFrameworkCore.Design插件  关闭VS重新加载项目即可;

8、更新实体表数据到数据库:dotnet ef database update 

注:更新数据库 必须保证 XXX.DbMigrator 项目中的数据库配置文件正确;

9、错误提示:The Entity Framework tools version '3.1.4' is older than that of the runtime '5.0.0'. Update the tools for the latest features and bug fixes.

问题原因:The EF Core tools version 版本需要升级

解决方案:dotnet tool update -g dotnet-ef  升级到最新  或者指定具体版本  dotnet tool update --global dotnet-ef --version 3.1.0

七、生成项目运行所需种子数据:如 管理员账号密码

1、将 AoRuiDe.GasMonitoring.DbMigrator  设为启动项目

2、Ctrl+F5 运行启动  自动完成种子数据生成

3、也可以通过控制台程序 -> cd 到 src\AoRuiDe.GasMonitoring.DbMigrator 目录 --> dotnet run 直接启动运行 生成种子数据到数据库

4、生成的默认账号密码理论上应该是:admin/1q2w3e*【实测密码不对】

八、运行项目:

1、启动项目:AoRuiDe.GasMonitoring.Web  

2、打开首页:进入 https://localhost:44350 注册一个新账号密码进行登录  

3、接口测试:进入 https://localhost:44350/swagger/index.html  API管理界面  测试Api接口

4、问题:如果项目添加了认证服务:-separate-identity-server   会出现登录认证服务项目页面加载特别缓慢 1分钟足有才能显示界面;

问题原因:为了多应用程序共享数据 认证项目后端默认使用了 Redis 相关的配置   而测试机 未安装 Redis服务 导致的

解决方案:安装一个Redis服务 appsetting.json 中配置好对应的 Redis访问连接

//简单屏蔽此代码貌似无效,最好安装一个Redis服务 
//解决方案:安装一个Redis服务 appsetting.json 中配置好对应的 Redis访问连接
private void ConfigureRedis(ServiceConfigurationContext context, IConfiguration onfiguration, IWebHostEnvironment hostingEnvironment)
 {
     if (!hostingEnvironment.IsDevelopment())
     {
         var redis = ConnectionMultiplexer.Connect(configuration["Redis:Configuration"]);
         context.Services
             .AddDataProtection()
             .PersistKeysToStackExchangeRedis(redis, "GasMonitoring-Protection-Keys");
     }
 }

更多推荐