1. 程式人生 > 其它 >Abp vNext 基礎篇丨框架搭建

Abp vNext 基礎篇丨框架搭建

介紹

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 = "[email protected]";
        public const string AdminPasswordDefaultValue = "123456";
    }


   await _dataSeeder.SeedAsync(new DataSeedContext(tenant?.Id)
                .WithProperty(IdentityDataSeedContributor.AdminEmailPropertyName, CoreIdentityConsts.AdminEmailDefaultValue)
                .WithProperty(IdentityDataSeedContributor.AdminPasswordPropertyName, CoreIdentityConsts.AdminPasswordDefaultValue)
            );


Bcvp.Blog.Core.Domain層中在CoreDomainModule.csConfigureServices方法中加入如下程式碼修改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