-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
53 lines (43 loc) · 1.25 KB
/
main.go
File metadata and controls
53 lines (43 loc) · 1.25 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
package main
import (
"context"
"fmt"
assemble "github.com/xfrr/assemble"
"github.com/xfrr/assemble/example/di"
)
func main() {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
// Build the container using the compiled Assemble function
container, err := di.AssembleServer()
if err != nil {
panic(err)
}
// Alternatively, use the assemble.Assemble function with the Core variable
// to build the container dynamically
// container, err := assemble.Assemble(Core)
// if err != nil {
// panic(err)
// }
// Start the container
if startErr := container.Start(context.Background()); startErr != nil {
panic(startErr)
}
// Resolve after Start using the container directly (it implements assemble.Resolver)
_, err = assemble.Get[*di.Server](ctx, container)
if err != nil {
panic(err)
}
logger, err := assemble.Get[di.SimpleLogger](ctx, container)
if err != nil {
panic(err)
}
fmt.Println("----- Creation Order DOT -----")
fmt.Println(container.ExportCreationOrderDOT())
fmt.Println("----- Creation Order PlantUML -----")
fmt.Println(container.ExportCreationOrderPlantUML())
logger.Info("Server is running...")
if shutdownErr := container.Shutdown(context.Background()); shutdownErr != nil {
panic(shutdownErr)
}
}