-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.go
64 lines (53 loc) · 1.89 KB
/
app.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
package example
import (
"database/sql"
"github.com/dogmatiq/dogma"
"github.com/dogmatiq/example/domain"
"github.com/dogmatiq/example/projections"
"github.com/dogmatiq/projectionkit/sqlprojection"
)
// AppKey is the example application's identity key.
const AppKey = "22028264-0bca-43e1-8d9d-cd094efb10b7"
// App is a dogma.Application implementation for the example "bank" domain.
type App struct {
AccountAggregate domain.AccountHandler
CustomerAggregate domain.CustomerHandler
DailyDebitLimitAggregate domain.DailyDebitLimitHandler
TransactionAggregate domain.TransactionHandler
DepositProcess domain.DepositProcessHandler
OpenAccountForNewCustomerProcess domain.OpenAccountForNewCustomerProcessHandler
TransferProcess domain.TransferProcessHandler
WithdrawalProcess domain.WithdrawalProcessHandler
AccountProjection projections.AccountProjectionHandler
CustomerProjection projections.CustomerProjectionHandler
// ReadDB is the database to use for read-models. If it is nil the
// projection message handlers are omitted from the application
// configuration.
ReadDB *sql.DB
}
// Configure configures the Dogma engine for this application.
func (a *App) Configure(c dogma.ApplicationConfigurer) {
c.Identity("bank", AppKey)
c.RegisterAggregate(a.AccountAggregate)
c.RegisterAggregate(a.CustomerAggregate)
c.RegisterAggregate(a.DailyDebitLimitAggregate)
c.RegisterAggregate(a.TransactionAggregate)
c.RegisterProcess(a.DepositProcess)
c.RegisterProcess(a.OpenAccountForNewCustomerProcess)
c.RegisterProcess(a.TransferProcess)
c.RegisterProcess(a.WithdrawalProcess)
if a.ReadDB != nil { // TODO: Remove this when testkit is updated
c.RegisterProjection(
sqlprojection.New(
a.ReadDB,
&a.AccountProjection,
),
)
c.RegisterProjection(
sqlprojection.New(
a.ReadDB,
&a.CustomerProjection,
),
)
}
}