{"id":16946050,"url":"https://github.com/lsegal/dinit","last_synced_at":"2025-03-21T08:43:40.083Z","repository":{"id":65987778,"uuid":"125328025","full_name":"lsegal/dinit","owner":"lsegal","description":"Dependency Injection (DI) library for Go","archived":false,"fork":false,"pushed_at":"2018-03-18T00:13:06.000Z","size":18,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-26T05:23:32.398Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/lsegal.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":"2018-03-15T07:22:19.000Z","updated_at":"2019-10-14T12:56:07.000Z","dependencies_parsed_at":"2023-03-10T23:26:52.139Z","dependency_job_id":null,"html_url":"https://github.com/lsegal/dinit","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lsegal%2Fdinit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lsegal%2Fdinit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lsegal%2Fdinit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lsegal%2Fdinit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lsegal","download_url":"https://codeload.github.com/lsegal/dinit/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244767542,"owners_count":20507110,"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":[],"created_at":"2024-10-13T21:24:50.925Z","updated_at":"2025-03-21T08:43:40.060Z","avatar_url":"https://github.com/lsegal.png","language":"Go","readme":"# DInit\n\n[![GoDoc](https://godoc.org/github.com/lsegal/dinit?status.svg)](https://godoc.org/github.com/lsegal/dinit)\n[![Build Status](https://travis-ci.org/lsegal/dinit.svg?branch=master)](https://travis-ci.org/lsegal/dinit)\n[![Coverage Status](https://coveralls.io/repos/github/lsegal/dinit/badge.svg?branch=master)](https://coveralls.io/github/lsegal/dinit?branch=master)\n\nDInit is a library to initialize structs using Dependenci Injection (DI).\n\n## Installation\n\n```sh\ngo get -u github.com/lsegal/dinit\n```\n\n## Usage\n\nUse `dinit.Init(val1, val2, ...)` where arguments are either struct values,\nreferences, bare functions, or initializer functions that return struct values.\n\nDInit will then call your functions in the appropriate order to ensure that\nall functions have their arguments filled by the values provided in the\n`Init()` call.\n\nFor example, in the code below we have a `log.Logger` object, a `client` and\n`service`. The `service` depends on `log.Logger,` and `client` depends on\nboth `service` and `log.Logger`. When we call their initializers, only 1\ninstance of client and server are created:\n\n```go\nfunc newClient(l *log.Logger, svc lister) *client { /* ... */ }\nfunc newService(l *log.Logger) *service { /* ... */ }\n\nfunc main() {\n  l := log.New(os.Stdout, \"\", log.Lshortfile)\n  useClient := func(c *client) { c.PrintPeople() }\n  dinit.Init(newClient, useClient, newService, l)\n\n  // Output:\n  // main.go:40: Initializing service\n  // main.go:35: Initializing client\n  // main.go:30: Client asked for a list of people\n  // main.go:18: People: Sarah, Bob, André\n}\n```\n\nYou can see the full (runnable) example in `examples/client_server/main.go`.\n\n## Copyright \u0026 License\n\nCopyright (c) 2018 Loren Segal. All rights reserved.\n\nThis project is licensed under the MIT license, see `LICENSE` for details.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flsegal%2Fdinit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flsegal%2Fdinit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flsegal%2Fdinit/lists"}