-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexport.go
96 lines (79 loc) · 2.3 KB
/
export.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package ddd
import (
"github.com/antlinker/ddd/log"
)
var (
defaultDM = &domainManage{domains: make(map[string]Domain)}
)
// GetDomain 获取指定的领域
func GetDomain(domainid string) Domain {
return defaultDM.GetDomain(domainid)
}
// RegDomain 注册领域
func RegDomain(d Domain) {
defaultDM.RegDomain(d)
}
// // RegSubDomain 注册子域
// func RegSubDomain(d Domain, sub Domain) {
// d.regSubDomain(sub)
// }
// // RegAggregateRoot 向领域或者子域内注册聚合跟
// func RegAggregateRoot(d Domain, ar AggregateRoot) {
// d.regAggregateRoot(ar)
// }
// // SetRepoForARoot 为聚合根设置对应的仓储
// // 每个聚合根只能设置一个仓储
// func SetRepoForARoot(ar AggregateRoot, repo Repository) {
// ar.setRepository(repo)
// }
// // RegRepositoryByDomain 向领域注入仓储
// func RegRepositoryByDomain(d Domain, repo Repository) {
// d.regRepository(repo)
// }
// // RegService 向领域注入仓储
// func RegService(d Domain, svc DomainService) {
// d.regService(svc)
// }
// FindNode 查找领域对象节点
func FindNode(path string) (DomainNode, error) {
return defaultDM.FindNode(path)
}
// FindDomain 通过路径查找领域节点
func FindDomain(path string) (Domain, error) {
return defaultDM.FindDomain(path)
}
// FindAggregateRoot 通过路径查找聚合根
func FindAggregateRoot(path string) (AggregateRoot, error) {
return defaultDM.FindAggregateRoot(path)
}
// FindAggregate 通过路径查找聚合
func FindAggregate(path string) (Aggregate, error) {
return defaultDM.FindAggregate(path)
}
// FindDomainService 通过路径查找服务
func FindDomainService(path string) (DomainService, error) {
return defaultDM.FindDomainService(path)
}
// FindEntity 通过路径查找实例
func FindEntity(path string) (Entity, error) {
return defaultDM.FindEntity(path)
}
// FindRepository 通过路径查找仓储
func FindRepository(path string) (Repository, error) {
return defaultDM.FindRepository(path)
}
// PrintDomain 输出当前领域内的对象
func PrintDomain(d DomainNode) {
printDomain("", d)
}
func printDomain(pre string, d DomainNode) {
log.Infof("%s%s->%s", pre, d.ItemKind().Name(), d.DomainID())
children := d.getChildren()
if children != nil {
for _, v := range children {
for _, v := range v {
printDomain(pre+" ", v)
}
}
}
}