go-container

module
v1.0.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 29, 2024 License: Apache-2.0

Image README

go-container

Go Reference Image Image

Desc

  • go-container is a container pkg for go.

中文 | English

Download

go get -u github.com/deatil/go-container

Get Starting

global use

di := container.DI()

customer use

di := container.New()
package main

import (
    "fmt"
    "github.com/deatil/go-container/container"
)

type testBind struct {}

func (t *testBind) Data() string {
    return "testBind data"
}

func main() {
    // Bind func
    di := container.DI()
    di.Bind("testBind", func() *testBind {
        return &testBind{}
    })
    tb := di.Get("testBind")

    tb2, _ := tb.(*testBind)
    
    fmt.Printf("output: %s", tb2.Data())
    // output: testBind data
}

func useProvide() {
    // use Provide
    di := container.DI()
    di.Provide(func() *testBind {
        return &testBind{}
    })
    di.Invoke(func(tb *testBind) {
        fmt.Printf("output: %s", tb.Data())
        // output: testBind data
    })
}

LICENSE

  • The library LICENSE is Apache2, using the library need keep the LICENSE.

Image Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL