-
Notifications
You must be signed in to change notification settings - Fork 1
/
root.go
52 lines (47 loc) · 1.37 KB
/
root.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
// Copyright 2017 Granitic. All rights reserved.
// Use of this source code is governed by an Apache 2.0 license that can be found in the LICENSE file at the root of this project.
package gioc
import (
"github.com/vlorc/gioc/binder"
"github.com/vlorc/gioc/builder"
"github.com/vlorc/gioc/container"
"github.com/vlorc/gioc/depend"
"github.com/vlorc/gioc/factory"
"github.com/vlorc/gioc/invoker"
"github.com/vlorc/gioc/module"
"github.com/vlorc/gioc/provider"
"github.com/vlorc/gioc/register"
"github.com/vlorc/gioc/selector"
"github.com/vlorc/gioc/types"
"github.com/vlorc/gioc/utils"
)
// create a root container
func NewRootContainer() types.Container {
sel := selector.NewTypeSelector(binder.NewBinderFactory())
root := container.NewContainer(
register.NewRegister(sel),
provider.NewWithProvider(sel, nil),
)
for _, v := range []interface{}{
depend.NewDependencyFactory,
builder.NewBuilderFactory,
selector.NewSelectorFactory,
invoker.NewInvokerFactory,
register.NewRegisterFactory,
provider.NewProviderFactory,
} {
f, typ, _ := factory.NewMethodFactory(v, nil)
root.AsRegister().RegisterFactory(
factory.NewSingleFactory(f),
typ,
)
}
return root
}
// create a root module
func NewRootModule(table ...module.ModuleInitHandle) types.Module {
return module.NewModuleFor(
utils.Lazy(NewRootContainer).(func() types.Container),
table...,
)
}