-
Notifications
You must be signed in to change notification settings - Fork 0
/
memory.go
42 lines (37 loc) · 1.16 KB
/
memory.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
package memory
import (
"github.com/go-ee/utils/ehu"
"github.com/go-ee/utils/ehu/app"
"github.com/looplab/eventhorizon"
"github.com/looplab/eventhorizon/commandhandler/bus"
eb "github.com/looplab/eventhorizon/eventbus/local"
es "github.com/looplab/eventhorizon/eventstore/memory"
repo "github.com/looplab/eventhorizon/repo/memory"
)
func NewAppMemory(appInfo *app.Info, serverConfig *app.ServerConfig, secure bool) *app.Base {
// Create the event store.
eventStore, _ := es.NewEventStore()
// Create the event bus that distributes events.
eventBus := eb.NewEventBus(nil)
// Create the command bus.
commandBus := bus.NewCommandHandler()
repos := make(map[string]eventhorizon.ReadWriteRepo)
readRepos := func(name string, factory func() eventhorizon.Entity) (ret eventhorizon.ReadWriteRepo, err error) {
if item, ok := repos[name]; !ok {
repoInst := repo.NewRepo()
repoInst.SetEntityFactory(factory)
ret = repoInst
repos[name] = ret
} else {
ret = item
}
return
}
return app.NewAppBase(appInfo, serverConfig, secure,
&ehu.Middleware{
EventStore: eventStore,
EventBus: eventBus,
CommandBus: commandBus,
Repos: readRepos,
})
}