Skip to content
enorithPublic

About

No description or website provided.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

31 Commits

Folders and files

Repository files navigation

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)
}

About

No description or website provided.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages

⌂ 换网址