Fixed a problem with the injection code
This commit is contained in:
+6
-4
@@ -13,12 +13,14 @@ var (
|
|||||||
|
|
||||||
func DefineSingleton(ptr interface{}, constructor interface{}, args ...interface{}) {
|
func DefineSingleton(ptr interface{}, constructor interface{}, args ...interface{}) {
|
||||||
typ := reflect.TypeOf(ptr)
|
typ := reflect.TypeOf(ptr)
|
||||||
if definitions[typ] == nil {
|
provider := inject.NewProvider(constructor, args...)
|
||||||
Graph.Define(ptr, inject.NewProvider(constructor, args...))
|
|
||||||
|
if _, found := definitions[typ]; found {
|
||||||
|
ptr = definitions[typ]
|
||||||
} else {
|
} else {
|
||||||
Graph.Define(definitions[typ], inject.NewProvider(constructor, args...))
|
definitions[typ] = ptr
|
||||||
}
|
}
|
||||||
definitions[typ] = ptr
|
Graph.Define(ptr, provider)
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|||||||
Reference in New Issue
Block a user