depinject/depinject.go
func (di *dependencyInjector) createFromType(atype reflect.Type) reflect.Value {
	constructor, exists := di.registry[atype]
	if !exists {
		panic(fmt.Sprintf("Can't find a mapping to create a %s", atype))
	}

	constructorType := reflect.TypeOf(constructor)
	constructorArgs := []reflect.Value{}

	for i := 0; i < constructorType.NumIn(); i++ {
		t := constructorType.In(i)
		v := di.CreateFromType(t)
		constructorArgs = append(constructorArgs, v)
	}

	newObj := reflect.ValueOf(constructor).Call(constructorArgs)

	return newObj[0]
}
func (di *dependencyInjector) createFromType(atype reflect.Type) reflect.Value {
	constructor, exists := di.registry[atype]
	if !exists {
		panic(fmt.Sprintf("Can't find a mapping to create a %s", atype))
	}

	constructorType := reflect.TypeOf(constructor)
	constructorArgs := []reflect.Value{}

	for i := 0; i < constructorType.NumIn(); i++ {
		t := constructorType.In(i)
		v := di.CreateFromType(t)
		constructorArgs = append(constructorArgs, v)
	}

	newObj := reflect.ValueOf(constructor).Call(constructorArgs)

	return newObj[0]
}
func ( di * dependencyInjector ) createFromType ( atype reflect . Type ) reflect . Value { constructor , exists := di . registry [ atype ] if ! exists { panic ( fmt . Sprintf ( " " , atype ) ) } constructorType := reflect . TypeOf ( constructor ) constructorArgs := [ ] reflect . Value { } for i := 0 ; i < constructorType . NumIn ( ) ; i ++ { t := constructorType . In ( i ) v := di . CreateFromType ( t ) constructorArgs = append ( constructorArgs , v ) } newObj := reflect . ValueOf ( constructor ) . Call ( constructorArgs ) return newObj [ 0 ] }
// CreateFromType creates an instance of the given type
CreateFromType creates an instance of the given type