{"id":13413455,"url":"https://github.com/Fs02/wire","last_synced_at":"2025-03-14T19:32:17.957Z","repository":{"id":57485621,"uuid":"139835016","full_name":"Fs02/wire","owner":"Fs02","description":"Strict Runtime Dependency Injection for Golang","archived":false,"fork":false,"pushed_at":"2021-08-22T07:00:18.000Z","size":31,"stargazers_count":37,"open_issues_count":1,"forks_count":8,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-07-31T20:52:22.045Z","etag":null,"topics":["dependency-injection","dependency-injection-container","golang"],"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/Fs02.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":"Fs02"}},"created_at":"2018-07-05T10:42:24.000Z","updated_at":"2024-05-21T06:32:54.000Z","dependencies_parsed_at":"2022-09-11T16:01:11.385Z","dependency_job_id":null,"html_url":"https://github.com/Fs02/wire","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Fs02%2Fwire","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Fs02%2Fwire/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Fs02%2Fwire/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Fs02%2Fwire/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Fs02","download_url":"https://codeload.github.com/Fs02/wire/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243635439,"owners_count":20322941,"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","dependency-injection-container","golang"],"created_at":"2024-07-30T20:01:40.786Z","updated_at":"2025-03-14T19:32:17.633Z","avatar_url":"https://github.com/Fs02.png","language":"Go","readme":"# wire\n\n[![GoDoc](https://godoc.org/github.com/Fs02/wire?status.svg)](https://godoc.org/github.com/Fs02/wire) [![Build Status](https://travis-ci.org/Fs02/wire.svg?branch=master)](https://travis-ci.org/Fs02/wire) [![Go Report Card](https://goreportcard.com/badge/github.com/Fs02/wire)](https://goreportcard.com/report/github.com/Fs02/wire) [![Maintainability](https://api.codeclimate.com/v1/badges/7957f2fe0d2c6fd5d72c/maintainability)](https://codeclimate.com/github/Fs02/wire/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/7957f2fe0d2c6fd5d72c/test_coverage)](https://codeclimate.com/github/Fs02/wire/test_coverage)\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2FFs02%2Fwire.svg?type=shield)](https://app.fossa.io/projects/git%2Bgithub.com%2FFs02%2Fwire?ref=badge_shield)\n\nWire is runtime depedency injection/wiring for golang. It's designed to be strict to avoid your go application running without proper dependency injected.\n\nFeatures:\n\n- Strictly validates dependency and prevents missing or ambiguous dependency.\n- Check againts possible forgotten `wire` tag.\n- Easily connect and resolve object anywhere.\n- Annotates ambiguous interface type using connection name or implementation name.\n\n## Install\n\n```bash\ngo get github.com/Fs02/wire\n```\n\n## Example\n\n```golang\npackage wire_test\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/Fs02/wire\"\n)\n\ntype Listener struct{}\n\nfunc (listener Listener) Next() string {\n\treturn \"system\"\n}\n\ntype Printer interface {\n\tExec(string) error\n}\n\ntype SystemPrint struct {\n\tApp string `wire:\"\"`\n}\n\nfunc (systemPrint SystemPrint) Exec(msg string) error {\n\tfmt.Println(\"[\" + systemPrint.App + \"] System: \" + msg)\n\treturn nil\n}\n\ntype UserPrint struct {\n\tApp    string `wire:\"\"`\n\tTarget string\n}\n\nfunc (userPrint UserPrint) Exec(msg string) error {\n\tfmt.Println(\"[\" + userPrint.App + \"]\" + userPrint.Target + \": \" + msg)\n\treturn nil\n}\n\ntype Service struct {\n\t// Each of `wire`` tag below indicate fields to be wired with apporpriate component.\n\t// value inside `wire` tag indicate the name of the component and optionally it's type.\n\t// `wire` with empty value will be wired with default value (named using empty string).\n\t// Ambiguous field can be resolved by adding it's type, name or both (separated using comma) to the `wire` tag.\n\t// Don't worry if you forgot to add wire tag to an interface or a pointer, wire will warn you if any nil field are found.\n\t// To ignore wiring on specific field, you can use add `wire:\"-\"`.\n\tListener     Listener `wire:\"\"`\n\tSystemPrint  Printer  `wire:\",SystemPrint\"`\n\tFooUserPrint Printer  `wire:\"foo\"`\n\tBooUserPrint Printer  `wire:\"boo,UserPrint\"`\n}\n\nfunc (service Service) Update() error {\n\tswitch service.Listener.Next() {\n\tcase \"system\":\n\t\treturn service.SystemPrint.Exec(\"hello from system\")\n\tcase \"user-foo\":\n\t\treturn service.FooUserPrint.Exec(\"hello from foo\")\n\tcase \"user-boo\":\n\t\treturn service.BooUserPrint.Exec(\"hello from boo\")\n\tdefault:\n\t\treturn nil\n\t}\n}\n\nfunc init() {\n\t// add components to be wired by the library.\n\t// wire all components only once and as early as possible.\n\twire.Connect(\"CoolApp\")\n\twire.Connect(Listener{})                       // we don't need to pass by reference here, since it doesn't require any wiring.\n\twire.Connect(\u0026SystemPrint{})                   // we need to pass by reference it to allow wiring, wire will panic if we pass by value.\n\twire.Connect(\u0026UserPrint{Target: \"foo\"}, \"foo\") // wire a UserPrint named by \"foo\".\n\twire.Connect(\u0026UserPrint{Target: \"boo\"}, \"boo\") // wire a UserPrint named by \"boo\", wire will panic if there's duplicate components detected.\n\twire.Connect(\u0026Service{})\n\n\t// Apply wiring\n\twire.Apply()\n}\n\nfunc Example() {\n\t// Resolve a service component to be used later.\n\tvar service Service\n\twire.Resolve(\u0026service)\n\n\tservice.Update()\n\t// Output: [CoolApp] System: hello from system\n}\n```\n\n## License\n\nReleased under the [MIT License](https://github.com/Fs02/wire/blob/master/LICENSE)\n\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2FFs02%2Fwire.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2FFs02%2Fwire?ref=badge_large)","funding_links":["https://github.com/sponsors/Fs02"],"categories":["Miscellaneous","杂项","其他杂项","Microsoft Office","Dependency Injection","Go"],"sub_categories":["Dependency Injection","依赖注入","依赖性注入","Advanced Console UIs"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FFs02%2Fwire","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FFs02%2Fwire","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FFs02%2Fwire/lists"}