https://github.com/goapt/container
A simple dependency injection for golang
https://github.com/goapt/container
Last synced: about 2 months ago
JSON representation
A simple dependency injection for golang
- Host: GitHub
- URL: https://github.com/goapt/container
- Owner: goapt
- Created: 2020-01-16T02:11:28.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-01-16T02:51:55.000Z (over 5 years ago)
- Last Synced: 2024-06-19T14:53:21.404Z (11 months ago)
- Language: Go
- Size: 4.88 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Golang容器注入API设计
![]()
[](https://codecov.io/gh/goapt/container)## API 设计
### 注册容器
```golang
di := container.New()
// 绑定合约
di.Register(func() contract.User {
return &repostiory.User{}
})// 绑定实例而非接口,并且同时依赖参数的注入,而注入的参数必须已经被注册
di.Register(func(user contract.User) *service.User {
return &service.User{
User:user
}
})
```### 注入容器
```golang
//注入变量
var user *UserService
di.Make(&user)//注入函数参数
var user *UserService
di.Make(function(user *UserService){
//somthing
})
```