{"id":18457843,"url":"https://github.com/devs-group/godi","last_synced_at":"2026-01-08T01:03:06.246Z","repository":{"id":249715363,"uuid":"832323321","full_name":"devs-group/godi","owner":"devs-group","description":"A lightweight, type-safe Dependency Injection (DI) container for Go, leveraging generics for a clean and intuitive API.","archived":false,"fork":false,"pushed_at":"2024-07-22T19:54:33.000Z","size":3,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2024-11-06T08:15:49.437Z","etag":null,"topics":["dependency-injection","generics","generics-in-golang","go","golang","threadsafe"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/devs-group.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-07-22T19:36:06.000Z","updated_at":"2024-08-23T09:51:13.000Z","dependencies_parsed_at":"2024-07-22T23:41:53.003Z","dependency_job_id":null,"html_url":"https://github.com/devs-group/godi","commit_stats":null,"previous_names":["devs-group/godi"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devs-group%2Fgodi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devs-group%2Fgodi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devs-group%2Fgodi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devs-group%2Fgodi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/devs-group","download_url":"https://codeload.github.com/devs-group/godi/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":231182966,"owners_count":18340299,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dependency-injection","generics","generics-in-golang","go","golang","threadsafe"],"created_at":"2024-11-06T08:15:52.728Z","updated_at":"2026-01-08T01:03:06.200Z","avatar_url":"https://github.com/devs-group.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 🧙‍♂️ Godi - Go Dependency Injection Engine\n\nA lightweight, type-safe Dependency Injection (DI) container for Go, leveraging generics for a clean and intuitive API.\n\n## ✨ Features\n\n- Type-safe dependency registration and resolution using Go generics\n- Support for both singleton and transient lifecycles\n- Thread-safe operations\n- No reflection for improved performance\n- Simple and intuitive API\n\n## 🚀 Installation\n\nTo install the Godi Engine, use `go get`:\n\n```bash\ngo get github.com/devs-group/godi\n```\n\n## 🏁 Quick Start\n\nHere's a simple example of how to use the Godi Engine:\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"github.com/devs-group/godi\"\n)\n\ntype Database struct {\n\tConnectionString string\n}\n\ntype UserRepository struct {\n\tDB *Database\n}\n\ntype UserService struct {\n\tRepo *UserRepository\n}\n\nfunc main() {\n\tcontainer := godi.New()\n\n\t// Register services\n\tgodi.Register(container, func() *Database {\n\t\treturn \u0026Database{ConnectionString: \"example_connection_string\"}\n\t}, godi.Singleton)\n\n\tgodi.Register(container, func() *UserRepository {\n\t\tdb, _ := godi.Resolve[*Database](container)\n\t\treturn \u0026UserRepository{DB: db}\n\t}, godi.Transient)\n\n\tgodi.Register(container, func() *UserService {\n\t\trepo, _ := godi.Resolve[*UserRepository](container)\n\t\treturn \u0026UserService{Repo: repo}\n\t}, godi.Transient)\n\n\t// Resolve and use a service\n\tuserService, _ := godi.Resolve[*UserService](container)\n\tfmt.Printf(\"Connection string: %s\\n\", userService.Repo.DB.ConnectionString)\n}\n```\n\n## 📚 API Reference\n\n### Creating a Container\n\n```go\ncontainer := godi.New()\n```\n\n### Registering Services\n\n```go\ngodi.Register[T any](container *Container, constructor func() T, lifecycle Lifecycle)\n```\n\n- `container`: The DI container\n- `constructor`: A function that creates an instance of the service\n- `lifecycle`: Either `godi.Singleton` or `godi.Transient`\n\n### Resolving Services\n\n```go\nservice, err := godi.Resolve[T any](container *Container)\n```\n\n### Must Resolve (Panics on Error)\n\n```go\nservice := godi.MustResolve[T any](container *Container)\n```\n\n## 🔄 Lifecycle Management\n\n- **Singleton**: Only one instance is created and reused for all subsequent resolves.\n- **Transient**: A new instance is created each time the service is resolved.\n\n## 🔒 Thread Safety\n\nThe Godi Engine is designed to be thread-safe. You can use a single container across multiple goroutines without worrying about race conditions.\n\n## 🤝 Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request.\n\n## 📄 License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevs-group%2Fgodi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdevs-group%2Fgodi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevs-group%2Fgodi/lists"}