Add presingletons

Plumb blueprint's presingletons through register.go.

Test: m checkbuild
Change-Id: I5bc0f311740c9220f7afdf2999e6f080f5b0c5ab
This commit is contained in:
Colin Cross 2017-11-07 13:35:38 -08:00
parent 99c6dfaecc
commit 5a79c83893

View file

@ -31,6 +31,7 @@ type singleton struct {
}
var singletons []singleton
var preSingletons []singleton
type mutator struct {
name string
@ -60,6 +61,10 @@ func RegisterSingletonType(name string, factory blueprint.SingletonFactory) {
singletons = append(singletons, singleton{name, factory})
}
func RegisterPreSingletonType(name string, factory blueprint.SingletonFactory) {
preSingletons = append(preSingletons, singleton{name, factory})
}
type Context struct {
*blueprint.Context
}
@ -69,6 +74,10 @@ func NewContext() *Context {
}
func (ctx *Context) Register() {
for _, t := range preSingletons {
ctx.RegisterPreSingletonType(t.name, t.factory)
}
for _, t := range moduleTypes {
ctx.RegisterModuleType(t.name, t.factory)
}