介紹
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