-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdecorator.go
More file actions
83 lines (65 loc) · 1.44 KB
/
decorator.go
File metadata and controls
83 lines (65 loc) · 1.44 KB
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
package dimple
var _ DecoratorDef = (*decoratorDef)(nil)
// Decorator returns a new instance of DecoratorDef
func Decorator(id string, decorates string, factory Factory) DecoratorDef {
return &decoratorDef{
definition: definition{
id: id,
},
factory: factory,
decorates: decorates,
}
}
type decoratorDef struct {
definition
factory Factory
instance any
decorates string
decorated Definition
}
func (d *decoratorDef) Decorated() Definition {
return d.decorated
}
func (d *decoratorDef) Factory() Factory {
return d.factory
}
func (d *decoratorDef) Instance() any {
return d.instance
}
func (d *decoratorDef) Decorates() string {
return d.decorates
}
func (d *decoratorDef) WithID(id string) DecoratorDef {
c := d.clone()
c.id = id
return c
}
func (d *decoratorDef) WithFactory(factory Factory) DecoratorDef {
c := d.clone()
c.factory = factory
return c
}
func (d *decoratorDef) WithInstance(instance any) DecoratorDef {
c := d.clone()
c.instance = instance
return c
}
func (d *decoratorDef) WithDecorates(id string) DecoratorDef {
c := d.clone()
c.decorates = id
return c
}
func (d *decoratorDef) WithDecorated(def Definition) DecoratorDef {
c := d.clone()
c.decorated = def
return c
}
func (d *decoratorDef) clone() *decoratorDef {
return &decoratorDef{
definition: *d.definition.clone(),
factory: d.Factory(),
instance: d.Instance(),
decorates: d.Decorates(),
decorated: d.Decorated(),
}
}