Fixed a problem with the injection code

This commit is contained in:
Deluan 2016-03-03 13:14:05 -05:00
parent c9455e1955
commit f3ba23ef41
1 changed files with 6 additions and 4 deletions

View File

@ -13,12 +13,14 @@ var (
func DefineSingleton(ptr interface{}, constructor interface{}, args ...interface{}) {
typ := reflect.TypeOf(ptr)
if definitions[typ] == nil {
Graph.Define(ptr, inject.NewProvider(constructor, args...))
provider := inject.NewProvider(constructor, args...)
if _, found := definitions[typ]; found {
ptr = definitions[typ]
} else {
Graph.Define(definitions[typ], inject.NewProvider(constructor, args...))
definitions[typ] = ptr
}
definitions[typ] = ptr
Graph.Define(ptr, provider)
}
func init() {