推荐依赖注入库: go-container

tuzhiya · · 370 次点击 · 开始浏览    置顶

go-container 是使用go的反射使用的轻量级的依赖注入库,使用简单 下载: ~~~ go get -u github.com/deatil/go-container ~~~ 示例: ~~~ 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{} }) tb2 := di.Get("testBind").(*testBind) fmt.Printf("output: %s", tb2.Data()) // output: testBind data } ~~~ 项目地址: https://github.com/deatil/go-container

有疑问加站长微信联系(非本文作者)

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

370 次点击  ∙  1 赞  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传