-
Notifications
You must be signed in to change notification settings - Fork 0
/
service.go
56 lines (44 loc) · 923 Bytes
/
service.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
package dimple
var _ ServiceDef = (*serviceDef)(nil)
// Service returns a new instance of ServiceDef
func Service(id string, factory Factory) ServiceDef {
return &serviceDef{
definition: definition{
id: id,
},
factory: factory,
}
}
type serviceDef struct {
definition
factory Factory
instance any
}
func (s *serviceDef) clone() *serviceDef {
return &serviceDef{
definition: *s.definition.clone(),
factory: s.Factory(),
instance: s.Instance(),
}
}
func (s *serviceDef) WithID(id string) ServiceDef {
c := s.clone()
c.id = id
return c
}
func (s *serviceDef) WithFactory(factory Factory) ServiceDef {
c := s.clone()
c.factory = factory
return c
}
func (s *serviceDef) WithInstance(instance any) ServiceDef {
c := s.clone()
c.instance = instance
return c
}
func (s *serviceDef) Instance() any {
return s.instance
}
func (s *serviceDef) Factory() Factory {
return s.factory
}