Code Monkey home page Code Monkey logo

draw-lottery's Introduction

美团DDD实践 示例项目


说明

需求

  • 抽奖活动有活动限制,例如用户的抽奖次数限制,抽奖的开始和结束的时间等;
  • 一个抽奖活动包含多个奖品,可以针对一个或多个用户群体;
  • 奖品有自身的奖品配置,例如库存量,被抽中的概率等,最多被一个用户抽中的次数等等;
  • 用户群体有多种区别方式,如按照用户所在城市区分,按照新老客区分等;
  • 活动具有风控配置,能够限制用户参与抽奖的频率。

设计

整体需求划分为 M端-抽奖管理 和C端-用户抽奖两个子领域,针对用户抽奖领域设计

限界上下文

  • 划分为:抽奖、活动准入、风控、计数、库存 上下文

上下文映射

  • 梳理上下文关系

战术建模

  • 实体entity 值对象 value object 聚合根 aggregate 领域服务 领域事件

工程实现

模块划分

  • 按项目模块或包来划分
  • lottery 抽奖 risk control 风险控制 counter 计数上下文 condition 准入上下文 stock 库存上下文
  • 模块内组织:domain.entity 实体 domain.valobj 值对象 service 领域服务 repo 资源库 facade 防腐层

领域对象

  • DrawLottery 抽奖业务-匹配奖池 AwardPool 奖池匹配具体逻辑

资源库

  • DAO 数据访问对象 PO 持久化对象 Cache 缓存对象 Repository 整合资源库访问和存储逻辑

防腐层

  • 适配层,对外部上下文访问时进行转换处理

领域服务

  • 使用提供的领域模型对象、资源库、防腐层 提供对其它上下文的接口
  • 通过微服务架构部署领域服务

应用服务层

  • 连接前端和领域服务实现,完成功能,对外属于领域服务 对内属于应用服务

draw-lottery's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

draw-lottery's Issues

关于防御性逻辑的位置问题

你好,
我看到博客中介绍到防御性逻辑放在领域服务里,那领域对象中还需要吗?
如果都在领域服务里,那对服务的要求变高了,需要知道被调用的领域对象的判空、异常逻辑。
如果加在领域对象中,那么感觉领域服务除了串联行为外,没什么别的作用,并且不做防御,可能还会带来不必要的事务问题
还是说两个都加,这样的话,会不会造成浪费

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.