V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
brucetao2009
V2EX  ›  程序员

我用自己理解的领域驱动设计,写了一个基础开发平台,本着学习的心态和大家分享,欢迎大家提供意见或建议

  •  
  •   brucetao2009 · 2022-09-29 16:51:45 +08:00 · 1541 次点击
    这是一个创建于 546 天前的主题,其中的信息可能已经有所发展或是发生改变。

    我用自己理解的领域驱动设计写了一套单体应用基础开发平台, 前端用的以是 vue-element-admin 为基础构建的,其中加入了自己研发了定制化的组件以方便开发,比如 表格组件,

    代码示例:

    <cdp-table :table-config="tableConfig">
          <template v-slot:tableOperations="slotProps">
            <el-dropdown size="small" :hide-on-click="false" trigger="click">
              <el-button type="text" style="margin-left:10px" size="small">
                更 多<i class="el-icon-arrow-down el-icon--right" />
              </el-button>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item @click.native="resetPassword(slotProps)">重置密码</el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </template>
        </cdp-table>
    

    表格配置信息

          tableConfig: {
            title: '账户',
            url: '/api/v1/account',
            columns: [
              {
                name: 'username',
                type: 'input',
                label: '账号',
                formConfig: {
                  rules: [{ required: true, message: '账号不能为空' }]
                }
              },
              {
                name: 'name',
                formConfig: {
                  name: 'user_id',
                  type: 'user-select-table',
                  rules: [{ required: true, message: '请选择用户' }]
                },
                label: '用户名'
              },
              {
                name: 'nickname',
                type: 'input',
                label: '昵称'
              },
              {
                name: 'role_name',
                formConfig: {
                  name: 'role_ids',
                  type: 'select',
                  key: 'id',
                  value: 'name',
                  multiple: true,
                  url: '/api/v1/role/all'
                },
                searchConfig: {
                  hidden: true
                },
                label: '角色'
              },
              {
                name: 'status',
                type: 'select',
                label: '状态',
                align: 'center',
                formConfig: {
                  type: 'select'
                },
                searchConfig: {
                  type: 'select'
                },
                data: [
                  { key: 1, value: '新建', type: 'warning' },
                  { key: 2, value: '进行中', type: 'info' },
                  { key: 3, value: '通过', type: 'success' },
                  { key: 4, value: '拒绝', type: 'danger' }
                ]
              },
              {
                name: 'create_time',
                type: 'date',
                label: '创建时间',
                width: 180,
                formConfig: {
                  type: 'date',
                  hidden: true
                },
                searchConfig: {
                  type: 'date',
                  hidden: true
                }
              }
            ]
          }
    

    表单组件,

    <template>
      <div style="width:40%">
        <cdp-select-icon />
      </div>
    </template>
    <script>
    import CdpSelectIcon from '@/components/cdp-ui/CdpSelectIcon'
    export default {
      components: {
        CdpSelectIcon
      },
      data() {
        return {}
      },
      methods: {}
    }
    </script>
    
    

    后端以 spring-boot 为基础,使用了 mybatis-plus,mapstructs 等开源 jar 包 数据库以 mysql 做数据存储

    后面领域模型设计结构如下:

    image image

    前端界面如下:

    image image image image

    项目地址

    github:

    前端: https://github.com/kushu001/cdp-web-vue

    后端: https://github.com/kushu001/cdp

    gitee:

    前端: https://gitee.com/kushu001/cdp-web-vue

    后端: https://gitee.com/kushu001/cdp

    目前已经做完一版领域模型设计的改造,欢迎大家试用,有什么建议也可以跟我提,

    我知道在坛子里有很多大佬,我知道我写的很垃圾(^ ^),也知道市面上有很多差不多的开源项目,我写这个一方面是市面上没有找到好一点的相关领域架构设计的框架(有一些框架我也看不懂),所以我就尝试着自己写一套。

    在代码架构设计这块,我也一直处于摸索中,难免会有很多不足的地方,感谢大家能够批评指正,提供更好的建议,我一定会虚心采纳。

    谢谢

    6 条回复    2022-10-11 08:54:02 +08:00
    x500
        1
    x500  
       2022-09-29 19:50:48 +08:00
    看上去不错
    jones2000
        2
    jones2000  
       2022-09-29 20:34:11 +08:00
    东西太多, 而且基本都是用库,对自己理解框架没有什么帮助,只是把这些库组装起来,也不明白什么为什么这些库要这样设计。最好是不用库,自己实现,这样才能明白别人为什么要这么设计。
    yule111222
        3
    yule111222  
       2022-09-30 14:44:36 +08:00
    建议把 domain 层单独做一个模块,几乎不添加外部依赖,让其他模块都去依赖 domain 层
    brucetao2009
        4
    brucetao2009  
    OP
       2022-10-01 19:20:44 +08:00
    @yule111222 单独一个模块是指? 我现在是 domain 单独一个层的,domain 基本没有依赖,只做业务领域模型,我在领域模型构建上还是觉得有所欠缺,后面等我理解更深一步了,会再对代码进行优化
    brucetao2009
        5
    brucetao2009  
    OP
       2022-10-01 19:23:16 +08:00
    @jones2000 用库没问题吧,不影响领域驱动设计啊,而且我也只是用了基础库,总不能让我再去实现一个持久层吧(*^o^*)
    yule111222
        6
    yule111222  
       2022-10-11 08:54:02 +08:00
    @brucetao2009 单独的 maven module,从依赖关系上彻底隔绝向外依赖的可能性
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5204 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 01:23 · PVG 09:23 · LAX 18:23 · JFK 21:23
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.