介绍

很久没有更新博客了,之前想更新但是发现博客园崩了,外加工作上的调换也比较忙,最近有了点时间我来继续更新下这个系列的文章。

今年3月份我带着我们研发组同事,将公司产品从老Abp重构到Abp vNext目前已经上线,我非常确认Abp vNext完全可以应用到生产环境,并且他足以支撑超复杂业务的系统开发。

很多人提到Abp就想到DDD,这很好,但是Abp并不是要求你一定要DDD,很多人在社区在群里说你不DDD你用Abp还不如不用,Abp你用来开发系统太重了,我其实很像问一下说出这些话的人,你深入用过Abp嘛?你用它开发过复杂的业务系统嘛?你能保证你现在使用的系统能够持久更新嘛?你说Abp很重我就想知道他重的点在哪里?(此处欢迎大佬找我探讨)

这次连载我将由浅入深的来给大家把 Abp vNext 过一遍,该项目作为老张的哲学Blog.Core博客系统姊妹篇,用比较简单的业务来演示你该如何开始使用Abp vNext,DDD我也会涉及到,如果时间允许IdentityServer和模块化我也会讲,反正就是过一遍让你不要太触怕这个东西,话不多说咱们还是直接上项目比较实在。

开始

Abp官网:https://abp.io/

直接创建项目,项目名称:Blog.Core.AbpvNext 我完全是为了看着方便这么叫,注意我选择的Ui是Angular,采用方案是将服务器端和授权分离为两个应用程序,如下图所示。

项目下载下来后修改DbMigrator、Host、IdentityServer的appsettings.json数据库连接字符串。

然后启动DbMigrator生成数据库,生成出来的数据库如下图所示,数据库表包含IdentityServer、用户、角色、组织、审计、Entity、安全、Feature、权限、日志、后台任务、设置等这几类。

项目介绍

我之前写过一个博客站点,如图所示我就根据这个博客站点来简单的分析下模型,模型如下图所示,后面我们会根据业务在进行修改。

创建模型

根据上面的模型把Entity创建一下,目录结构看下图

  public class SiteUser : FullAuditedAggregateRoot<Guid>
{
/// <summary>
/// 用户名
/// </summary>
public string UserName { get; set; }
/// <summary>
/// 用户
/// </summary>
public string Name { get; set; }
/// <summary>
/// 密码
/// </summary>
public string PassWord { get; set; }
/// <summary>
/// 头像
/// </summary>
public string HeadPortrait { get; set; }
/// <summary>
/// 邮箱
/// </summary>
public string Email { get; set; }
/// <summary>
/// 介绍
/// </summary>
public string Introduce { get; set; }
}
    public class Question:FullAuditedAggregateRoot<Guid>
{
/// <summary>
/// 标题
/// </summary>
public string Title { get; set; }
/// <summary>
/// 内容
/// </summary>
public string Content { get; set; }
/// <summary>
/// 类别
/// </summary>
public string Tag { get; set; }
/// <summary>
/// 访问量
/// </summary>
public int Traffic { get; set; } /// <summary>
/// 问答评论
/// </summary>
public virtual ICollection<QuestionComment> QuestionComments { get; set; }
}
    public class QuestionComment:FullAuditedAggregateRoot<Guid>
{
/// <summary>
/// 内容
/// </summary>
public string Content { get; set; } /// <summary>
/// 是否采纳
/// </summary>
public bool IsAdoption { get; set; } /// <summary>
/// 问答信息
/// </summary>
public virtual Question Question { get; set; }
}
    /// <summary>
/// 文章
/// </summary>
public class Article: FullAuditedAggregateRoot<Guid>
{
/// <summary>
/// 标题
/// </summary>
public string Title { get; set; }
/// <summary>
/// 封面
/// </summary>
public string Cover { get; set; }
/// <summary>
/// 内容
/// </summary>
public string Content { get; set; }
/// <summary>
/// 类别
/// </summary>
public string Tag { get; set; }
/// <summary>
/// 访问量
/// </summary>
public int Traffic { get; set; }
/// <summary>
/// 文章评论
/// </summary>
public virtual ICollection<ArticleComment> ArticleComments { get; set; } = new List<ArticleComment>(); }
    public class ArticleComment:FullAuditedAggregateRoot<Guid>
{
/// <summary>
/// 内容
/// </summary>
public string Content { get; set; } /// <summary>
/// 问答Id
/// </summary>
public Guid QuestionId { get; set; }
}

加入上下文并创建映射

在 EntityFrameworkCore层 AbpvNextDbContext 中 将Entity加入到上下文。


public class AbpvNextDbContext : AbpDbContext<AbpvNextDbContext>
{ public DbSet<Article> Articles { get; set; } public DbSet<ArticleComment> ArticleComments { get; set; } public DbSet<Question> Questions { get; set; } public DbSet<QuestionComment> QuestionComments { get; set; } public DbSet<SiteUser> SiteUsers { get; set; }
}

创建 EntityConfigurationGroup 文件夹,创建数据映射配置,如图所示

public class SiteUserCfg : IEntityTypeConfiguration<SiteUser>
{
public void Configure(EntityTypeBuilder<SiteUser> builder)
{
builder.ToTable(AbpvNextConsts.DbTablePrefix + "SiteUser", AbpvNextConsts.DbSchema);
builder.ConfigureByConvention(); builder.Property(e => e.UserName).HasMaxLength(128);
builder.Property(e => e.Name).HasMaxLength(128);
builder.Property(e => e.PassWord).HasMaxLength(256);
builder.Property(e => e.Email).HasMaxLength(128);
builder.Property(e => e.HeadPortrait).HasMaxLength(512);
builder.Property(e => e.Introduce).HasMaxLength(1024); }
}
 public  class ArticleCfg : IEntityTypeConfiguration<Article>
{
public void Configure(EntityTypeBuilder<Article> builder)
{
builder.ToTable(AbpvNextConsts.DbTablePrefix + "Article", AbpvNextConsts.DbSchema);
builder.ConfigureByConvention(); builder.Property(e => e.Title).HasMaxLength(128);
builder.Property(e => e.Cover).HasMaxLength(1024);
// builder.Property(e => e.Content).HasMaxLength(128);
builder.Property(e => e.Tag).HasMaxLength(128); builder.HasMany(e => e.ArticleComments).WithOne()
.HasForeignKey(x => x.ArticleId).IsRequired(false);
}
}
  public class ArticleCommentCfg : IEntityTypeConfiguration<ArticleComment>
{
public void Configure(EntityTypeBuilder<ArticleComment> builder)
{
builder.ToTable(AbpvNextConsts.DbTablePrefix + "ArticleComment", AbpvNextConsts.DbSchema);
builder.ConfigureByConvention(); builder.Property(e => e.Content).HasMaxLength(1024); }
}
    public class QuestionCfg : IEntityTypeConfiguration<Question>
{
public void Configure(EntityTypeBuilder<Question> builder)
{
builder.ToTable(AbpvNextConsts.DbTablePrefix + "Question", AbpvNextConsts.DbSchema);
builder.ConfigureByConvention(); builder.Property(e => e.Title).HasMaxLength(128);
// builder.Property(e => e.Content).HasMaxLength(128);
builder.Property(e => e.Tag).HasMaxLength(128); builder.HasMany(e => e.QuestionComments).WithOne()
.HasForeignKey(x => x.QuestionId).IsRequired(false);
}
}
    public class QuestionCommentCfg : IEntityTypeConfiguration<QuestionComment>
{
public void Configure(EntityTypeBuilder<QuestionComment> builder)
{ builder.ToTable(AbpvNextConsts.DbTablePrefix + "QuestionComment", AbpvNextConsts.DbSchema);
builder.ConfigureByConvention(); builder.Property(e => e.Content).HasMaxLength(1024);
}
}

加入到配置上下文

    public static class AbpvNextDbContextModelCreatingExtensions
{
public static void ConfigureAbpvNext(this ModelBuilder builder)
{
Check.NotNull(builder, nameof(builder)); // 文章
builder.ApplyConfiguration(new ArticleCfg()); builder.ApplyConfiguration(new ArticleCommentCfg()); // 问答
builder.ApplyConfiguration(new QuestionCfg()); builder.ApplyConfiguration(new QuestionCommentCfg()); // 用户
builder.ApplyConfiguration(new SiteUserCfg());
}
}

创建迁移选择 EntityFrameworkCore.DbMigrations 执行 Add-Migration Init_App_Db .

结语

该项目存放仓库在 https://github.com/BaseCoreVueProject/Blog.Core.AbpvNext

QQ群:867095512

项目开发过程中可能随时根据想法进行变化,加油!!!

最新文章

  1. java获取年份的后两位
  2. linux定时执行任务
  3. .NET Core常用配置文件示例
  4. Environment中针对的读写权限判断
  5. android代码设置、打开WLAN wifi热点及热点的连接
  6. CSS的浮动和清除
  7. codeforces D. Pashmak and Parmida&#39;s problem
  8. 类别sort使用排序
  9. 3、FileInputStream---&gt;类文件输入流(读取文件数据)
  10. http的状态码(中英文)
  11. ecb gud
  12. javascript 基础系列(一)
  13. iOS调用另一个程序
  14. 通过批处理 安装 mongodb和设置身份验证
  15. [POJ 1006]生理周期
  16. g++和gcc的相同点和区别
  17. 你不得不用的MAC软件开发工具软件,个个万里挑一
  18. analyse idoc by creation date
  19. Echarts的一些总结
  20. mysql命令行各个参数解释

热门文章

  1. 重新整理 .net core 实践篇—————服务的配置更新[十三]
  2. .Net之简单通知服务
  3. FFmpeg集成到GPU
  4. java容器学习笔记
  5. 信道均衡之非线性均衡——Tomlinson-Harashima Precoding(THP)
  6. 让Github畅通无阻,FastGithub1.0.0发布
  7. C#构造函数中:this()的作用
  8. Java8新特性代码示例(附注释)- 方法引用,Optional, Stream
  9. 使用python脚本统一重命名训练图片文件名
  10. MetingJS 是如何配合 Aplayer 加载歌单的?