-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdomain.go
145 lines (131 loc) · 3.03 KB
/
domain.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
package ddd
import (
"github.com/antlinker/ddd/path"
)
var (
_ Domain = &BaseDomain{}
)
// BaseDomain 基础领域实现,其他领域实现需要集成该结构体
type BaseDomain struct {
domain
}
// domain 实现Domain接口
type domain struct {
node
globalStore globalStore
// children map[string]Domain
// services map[string]DomainService
// repositorys map[string]Repository
// aggregateRoots map[string]AggregateRoot
//parent Domain
}
func (d *domain) Init(self DomainNode, parent DomainNode, domainID string) {
if parent == nil {
d.path = path.NewDomainPath(domainID)
}
d.init(self, parent, path.Domain, domainID, false)
// if d.aggregateRoots == nil {
// d.aggregateRoots = make(map[string]AggregateRoot)
// }
// d.path = path.NewDomainPath(domainID)
// d.pathItem = d.path.Next()
// d.domainID = domainID
// if parent != nil {
// dp, ok := parent.(Domain)
// if !ok {
// panic(fmt.Sprintf("初始化领域%s失败,上级节点不是一个有效的领域节点", domainID))
// }
// d.parent = dp
// d.resetParent(parent)
// }
// d.regSubDomain(self.(Domain))
}
func (d *domain) GlobalStorer() GlobalStorer {
return &d.globalStore
}
func (d *domain) IsRoot() bool {
return d.parent == nil
}
// 通过服务id获取域服务
func (d *domain) ServiceByID(serviceID string) DomainService {
if s, ok := d.getNode(path.Service, serviceID); ok {
if ds, o := s.(DomainService); o {
return ds
}
}
return nil
}
// 获取域内所有服务
func (d *domain) Services() (out []DomainService) {
if m, ok := d.getNodes(path.Service); ok {
for _, s := range m {
if ds, o := s.(DomainService); o {
out = append(out, ds)
}
}
}
return
}
// 获取域内所有的实例名
func (d *domain) EntityNames() []string {
// TODO 未实行
return nil
}
func (d *domain) EntityByID(id string) Entity {
// TOTO 未实现
return nil
}
func (d *domain) RepositoryByID(repoID string) Repository {
if s, ok := d.getNode(path.Repository, repoID); ok {
if ds, o := s.(Repository); o {
return ds
}
}
return nil
}
// 通过聚合根唯一标识获取聚合根
func (d *domain) AggregateRootByID(id string) AggregateRoot {
if s, ok := d.getNode(path.AggregateRoot, id); ok {
if ds, o := s.(AggregateRoot); o {
return ds
}
}
return nil
}
// 获取域内所有聚合根
func (d *domain) AggregateRoots() (out []AggregateRoot) {
if m, ok := d.getNodes(path.AggregateRoot); ok {
for _, s := range m {
if ds, o := s.(AggregateRoot); o {
out = append(out, ds)
}
}
}
return
}
func (d *domain) ParentDomain() Domain {
if d.parent != nil {
return d.parent.(Domain)
}
return nil
}
func (d *domain) SubDomains() (out map[string]Domain) {
out = make(map[string]Domain)
if m, ok := d.getNodes(path.Domain); ok {
for _, s := range m {
if ds, o := s.(Domain); o {
out[ds.DomainID()] = ds
}
}
}
return
}
// 获取指定子域
func (d *domain) SubDomain(id string) Domain {
if s, ok := d.getNode(path.Domain, id); ok {
if ds, o := s.(Domain); o {
return ds
}
}
return nil
}