# README
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()
// bind
c.BindFunc(Foo{}, func(c *container.Container) (reflect.Value, error) {
return reflect.ValueOf(Foo{"foo"}), nil
}, false)
// get instance
v, _ := c.Instance(Foo{})
fmt.Println(v.Interface().(Foo).name)
var f Foo
// get instance
c.InstanceFor(Foo{}, &f)
fmt.Println(f.name)
// bind with 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)
}
# Functions
No description provided by the author
# Structs
Container is a IoC-Container.
No description provided by the author
No description provided by the author
# Type aliases
ConditionInjectionFunc conditional injection function.
InjectionFunc injection function.
InstanceRegister register instance for container.