depinject/depinject.go
func (di *dependencyInjector) Register(constructorFunc interface{}) error {
	constructorType := reflect.TypeOf(constructorFunc)

	if (constructorType.Kind() != reflect.Func) || (constructorType.NumOut() != 1) {
		return constructorErr
	}
	outType := constructorType.Out(0)

	// make sure we can resolve the constuctor arguments
	for i := 0; i < constructorType.NumIn(); i++ {
		inType := constructorType.In(i)
		_, ok := di.registry[inType]
		if !ok {
			return fmt.Errorf("Can't resolve function arguments - can't find a %s for a %s\n", inType, outType)
		}
	}

	di.registry[outType] = constructorFunc

	return nil
}
func (di *dependencyInjector) Register(constructorFunc interface{}) error {
	constructorType := reflect.TypeOf(constructorFunc)

	if (constructorType.Kind() != reflect.Func) || (constructorType.NumOut() != 1) {
		return constructorErr
	}
	outType := constructorType.Out(0)

	// make sure we can resolve the constuctor arguments
	for i := 0; i < constructorType.NumIn(); i++ {
		inType := constructorType.In(i)
		_, ok := di.registry[inType]
		if !ok {
			return fmt.Errorf("Can't resolve function arguments - can't find a %s for a %s\n", inType, outType)
		}
	}

	di.registry[outType] = constructorFunc

	return nil
}
func ( di * dependencyInjector ) Register ( constructorFunc interface { } ) error { constructorType := reflect . TypeOf ( constructorFunc ) if ( constructorType . Kind ( ) != reflect . Func ) || ( constructorType . NumOut ( ) != 1 ) { return constructorErr } outType := constructorType . Out ( 0 ) // make sure we can resolve the constuctor arguments for i := 0 ; i < constructorType . NumIn ( ) ; i ++ { inType := constructorType . In ( i ) _ , ok := di . registry [ inType ] if ! ok { return fmt . Errorf ( " \n " , inType , outType ) } } di . registry [ outType ] = constructorFunc return nil }
// Register registers a constructor function
// with the DI container
Register registers a constructor function with the DI container