mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-04 13:07:36 +03:00
27 lines
556 B
Go
27 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()
|
|
}
|