-
Notifications
You must be signed in to change notification settings - Fork 0
/
configurer.go
94 lines (78 loc) · 2.02 KB
/
configurer.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
package engine
import (
"context"
"github.com/dogmatiq/enginekit/config"
"github.com/dogmatiq/enginekit/message"
"github.com/dogmatiq/testkit/engine/controller"
"github.com/dogmatiq/testkit/engine/controller/aggregate"
"github.com/dogmatiq/testkit/engine/controller/integration"
"github.com/dogmatiq/testkit/engine/controller/process"
"github.com/dogmatiq/testkit/engine/controller/projection"
)
type configurer struct {
engine *Engine
}
func (c *configurer) VisitApplicationConfig(ctx context.Context, cfg *config.ApplicationConfig) error {
c.engine.roles = cfg.Roles
for _, h := range cfg.HandlersByName {
if err := h.Accept(ctx, c); err != nil {
return err
}
}
return nil
}
func (c *configurer) VisitAggregateConfig(_ context.Context, cfg *config.AggregateConfig) error {
c.registerController(
aggregate.NewController(
cfg.HandlerName,
cfg.Handler,
&c.engine.messageIDs,
cfg.ProducedMessageTypes(),
),
cfg.ConsumedMessageTypes(),
)
return nil
}
func (c *configurer) VisitProcessConfig(_ context.Context, cfg *config.ProcessConfig) error {
c.registerController(
process.NewController(
cfg.HandlerName,
cfg.Handler,
&c.engine.messageIDs,
cfg.ProducedMessageTypes(),
),
cfg.ConsumedMessageTypes(),
)
return nil
}
func (c *configurer) VisitIntegrationConfig(_ context.Context, cfg *config.IntegrationConfig) error {
c.registerController(
integration.NewController(
cfg.HandlerName,
cfg.Handler,
&c.engine.messageIDs,
cfg.ProducedMessageTypes(),
),
cfg.ConsumedMessageTypes(),
)
return nil
}
func (c *configurer) VisitProjectionConfig(_ context.Context, cfg *config.ProjectionConfig) error {
c.registerController(
projection.NewController(
cfg.HandlerName,
cfg.Handler,
),
cfg.ConsumedMessageTypes(),
)
return nil
}
func (c *configurer) registerController(
ctrl controller.Controller,
types map[message.Type]message.Role,
) {
c.engine.controllers[ctrl.Name()] = ctrl
for t := range types {
c.engine.routes[t] = append(c.engine.routes[t], ctrl)
}
}