forked from i-love-flamingo/flamingo-commerce
-
Notifications
You must be signed in to change notification settings - Fork 0
/
module.go
79 lines (67 loc) · 1.99 KB
/
module.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
package sourcing
import (
"flamingo.me/dingo"
"flamingo.me/flamingo-commerce/v3/cart/domain/validation"
"flamingo.me/flamingo-commerce/v3/sourcing/domain/fake"
restrictors "flamingo.me/flamingo-commerce/v3/sourcing/domain/restrictor"
"flamingo.me/flamingo-commerce/v3/cart"
"flamingo.me/flamingo-commerce/v3/sourcing/application"
"flamingo.me/flamingo-commerce/v3/sourcing/domain"
)
type (
// Module registers sourcing module
Module struct {
useDefaultSourcingService bool
enableQtyRestrictor bool
useFakeService bool
}
)
// Inject dependencies
func (m *Module) Inject(
config *struct {
UseDefaultSourcingService bool `inject:"config:commerce.sourcing.useDefaultSourcingService,optional"`
EnableQtyRestrictor bool `inject:"config:commerce.sourcing.enableQtyRestrictor,optional"`
UseFakeService bool `inject:"config:commerce.sourcing.fake.enable, optional"`
},
) {
if config != nil {
m.useDefaultSourcingService = config.UseDefaultSourcingService
m.enableQtyRestrictor = config.EnableQtyRestrictor
m.useFakeService = config.UseFakeService
}
}
// Configure module
func (m *Module) Configure(injector *dingo.Injector) {
if m.useDefaultSourcingService {
injector.Bind(new(domain.SourcingService)).To(domain.DefaultSourcingService{})
}
if m.enableQtyRestrictor {
injector.Bind(new(validation.MaxQuantityRestrictor)).To(restrictors.Restrictor{})
}
if m.useFakeService {
injector.Override(new(domain.SourcingService), "").To(fake.SourcingService{})
}
injector.Bind(new(application.SourcingApplication)).To(application.Service{})
}
// Depends on other modules
func (m *Module) Depends() []dingo.Module {
return []dingo.Module{
new(cart.Module),
}
}
// CueConfig defines the sourcing module configuration
func (m *Module) CueConfig() string {
// language=cue
return `
commerce: {
sourcing: {
useDefaultSourcingService: bool | *true
enableQtyRestrictor: bool | *false
fake: {
enable: bool | *false
jsonPath: string | *""
}
}
}
`
}