Started implementing getIndex, now with TDD (brought to you by DI)!

This commit is contained in:
Deluan 2016-03-01 12:35:30 -05:00
parent b2cdf8cadb
commit 2bb4c74ba6
7 changed files with 129 additions and 21 deletions

View file

@ -1,9 +1,27 @@
package utils
import "github.com/karlkfi/inject"
import (
"github.com/karlkfi/inject"
"reflect"
)
var Graph inject.Graph
var (
definitions map[reflect.Type]interface{}
)
func DefineSingleton(ptr interface{}, constructor interface{}, args ...interface{}) {
typ := reflect.TypeOf(ptr)
if definitions[typ] == nil {
Graph.Define(ptr, inject.NewProvider(constructor, args...))
} else {
Graph.Define(definitions[typ], inject.NewProvider(constructor, args...))
}
definitions[typ] = ptr
}
func init() {
definitions = make(map[reflect.Type]interface{})
Graph = inject.NewGraph()
}