介绍
ABP目前的最新版本是4.4
也是最近才发布的,文章目前采用的是Angular作为UI框架,使用Entity Framework Core作为数据库提供者,如果你想用其他UI框架需要自己完成欢迎提交(pr)
创建项目
在 https://abp.io/ 首页,点击开始创建项目,项目名称Bcvp.Blog.Core
,勾选Tiered,ABP默认采用Ids4授权,勾选后他会将Ids4单独分离一层出来。
启动项目
项目下载下来后打开项目修改appsettings.json
的字符串连接,这里有三处要改分别是DbMigrator、HttpApi.Host、IdentityServer.
另外Abp项目默认采用Redis作为缓存提供者,如果你不想使用Redis可以直接删掉或者加一个"IsEnabled":"false"
来关闭redis。
上面的完成后将DbMigrator
设为启动项目,在程序包管理控制台选择Bcvp.Blog.Core.EntityFrameworkCore
输入Add-Migration Init
生成迁移文件。然后启动DbMigrator
运行项目该项目会执行迁移并添加种子数据,这里我说一下种子数据,ABP默认生成的种子数据是HOST理解为最高管理员,具体代码可以看Bcvp.Blog.Core.Domain
下的CoreDbMigrationService.cs
,至于怎么自己写一个等后面业务用到的时候在单独讲。
private async Task SeedDataAsync(Tenant tenant = null)
{
Logger.LogInformation($"Executing {(tenant == null ? "host" : tenant.Name + " tenant")} database seed...");
await _dataSeeder.SeedAsync(new DataSeedContext(tenant?.Id)
.WithProperty(IdentityDataSeedContributor.AdminEmailPropertyName, IdentityDataSeedContributor.AdminEmailDefaultValue)
.WithProperty(IdentityDataSeedContributor.AdminPasswordPropertyName, IdentityDataSeedContributor.AdminPasswordDefaultValue)
);
}
数据都搞定了那就直接启动项目,因为创建项目的时候勾选了Tiered所以会生成2个Web项目,可以在解决方案上右键属性,多项目启动,启动后默认用户名:Admin 密码:1q2w3E*
修改配置
我本人脑子有时候不好使Abp密码我记不住所以很难受,对于有相同问题的朋友可以参照下面这样修改密码配置。
在Domain.Shared
层下面新建CoreIdentityConsts
用于用于更换Abp的默认HOST账号配置信息(这里我们要记住一个开发规范,聚合内的常量和枚举要放在Domain.Shared
层)。
public static class CoreIdentityConsts
{
public const string AdminEmailDefaultValue = "mrchujiu@abp.io";
public const string AdminPasswordDefaultValue = "123456";
}
// 网友补充:该代码在CoreDbMigrationService.cs 下的 SeedDataAsync函数
await _dataSeeder.SeedAsync(new DataSeedContext(tenant?.Id)
.WithProperty(IdentityDataSeedContributor.AdminEmailPropertyName, CoreIdentityConsts.AdminEmailDefaultValue)
.WithProperty(IdentityDataSeedContributor.AdminPasswordPropertyName, CoreIdentityConsts.AdminPasswordDefaultValue)
);
在Bcvp.Blog.Core.Domain
层中在CoreDomainModule.cs
的ConfigureServices
方法中加入如下代码修改Identity
配置,虽然关闭了限制但是因为我们没修改密码的页面暂时也只好删除数据库重新跑一下DbMigrator
迁移来做了,以后就123456
登录吧。
Configure<IdentityOptions>(options =>
{
options.Password.RequireNonAlphanumeric = false;
options.Password.RequireLowercase = false;
options.Password.RequireUppercase = false;
options.Password.RequireDigit = false;
});
结语
本节知识点:
- 1.一个基础的ABP框架
- 2.修改种子数据配置
联系作者:加群:867095512 @MrChuJiu