golang implement of IoC-Container
basic usage
package main
import (
"fmt"
"github.com/enorith/container"
"reflect"
)
type Foo struct{
name string
}
func main(){
c := container.New()
c.BindFunc(Foo{}, func(c *container.Container) (reflect.Value, error) {
return reflect.ValueOf(Foo{"foo"}), nil
}, false)
v, _ := c.Instance(Foo{})
fmt.Println(v.Interface().(Foo).name)
var f Foo
c.InstanceFor(Foo{}, &f)
fmt.Println(f.name)
c.BindFunc("foo", func(c *container.Container) (reflect.Value, error) {
return reflect.ValueOf(Foo{"foo"}), nil
}, false)
v2, _ := c.Instance("foo")
fmt.Println(v2.Interface().(Foo).name)
}