Skip to content

ymhhh/ddd-onion-sample

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ddd-onion-sample

DDD & onion architecture sample in Go.

目录结构

  • core — 数据模型(实体)
  • domain — 仓储接口与实现(端口/适配器中的端口)
  • handlers — 应用层用例(业务编排)
  • infrastructure — 组合根(Composition Root),负责依赖注入与启动

依赖方向:handlers → domain → coreinfrastructure 组装各层,main 仅引导启动。

运行

go run .
#
make build && ./bin/ddd-onion-sample

依赖注入

本项目使用显式构造函数注入,不再依赖反射或 ClassLoader:

repo := domain.NewUserMockRepo()
handler, _ := handlers.NewUserHandler(repo)
app, _ := infrastructure.NewApp(infrastructure.Config{})

替换 UserRepository 实现(如真实 DB)只需在 NewApp 中切换构造逻辑。

待完善

  • 增加标准文件说明:日志,配置等
  • 加入到 gorut 项目中,形成模板
  • HTTP 服务器接入

About

在洋葱(Onion)架构中实现领域驱动设计

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors