mirror of
https://github.com/navidrome/navidrome.git
synced 2024-09-10 11:32:48 +02:00
28 lines
556 B
Go
28 lines
556 B
Go
package utils
|
|
|
|
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()
|
|
}
|