Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/euskadi31/go-service
Simple Dependency Injection Container for Golang
https://github.com/euskadi31/go-service
dependency-injection dependency-manager go golang golang-library service-container service-factory
Last synced: about 2 months ago
JSON representation
Simple Dependency Injection Container for Golang
- Host: GitHub
- URL: https://github.com/euskadi31/go-service
- Owner: euskadi31
- License: mit
- Created: 2017-06-28T18:56:18.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2024-10-07T17:07:41.000Z (3 months ago)
- Last Synced: 2024-10-13T12:23:24.225Z (2 months ago)
- Topics: dependency-injection, dependency-manager, go, golang, golang-library, service-container, service-factory
- Language: Go
- Size: 49.8 KB
- Stars: 8
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
Go Service Container [![Last release](https://img.shields.io/github/release/euskadi31/go-service.svg)](https://github.com/euskadi31/go-service/releases/latest) [![Documentation](https://godoc.org/github.com/euskadi31/go-service?status.svg)](https://godoc.org/github.com/euskadi31/go-service)
====================[![Go Report Card](https://goreportcard.com/badge/github.com/euskadi31/go-service)](https://goreportcard.com/report/github.com/euskadi31/go-service)
| Branch | Status | Coverage |
|---------|--------|----------|
| master | [![Build Status](https://img.shields.io/travis/euskadi31/go-service/master.svg)](https://travis-ci.org/euskadi31/go-service) | [![Coveralls](https://img.shields.io/coveralls/euskadi31/go-service/master.svg)](https://coveralls.io/github/euskadi31/go-service?branch=master) |Simple Dependency Injection Container for Golang
## Example
```go
package mainimport (
"fmt"
"github.com/euskadi31/go-service"
)type MyService struct {
name string
}func (s *MyService) SetName(name string) {
s.name = name
}func (s *MyService) Name() string {
return s.name
}func main() {
sc := service.New()// Define service
sc.Set("my.service", func(c service.Container) interface{} {
return &MyService{}
})// Extend service
sc.Extend("my.service", func(s *MyService) *MyService {
s.SetName("My Service")return s
})// Call service
myService := sc.Get("my.service").(*MyService)fmt.Printf("Service Name: %s", myService.Name())
}```
## License
go-service is licensed under [the MIT license](LICENSE.md).