{"id":21966678,"url":"https://github.com/4strodev/wiring","last_synced_at":"2025-10-10T12:30:53.488Z","repository":{"id":260766109,"uuid":"865409565","full_name":"4strodev/wiring","owner":"4strodev","description":"A dependency injection and autowiring library","archived":false,"fork":false,"pushed_at":"2025-01-09T22:18:16.000Z","size":83,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-09T22:32:27.289Z","etag":null,"topics":["autowiring","container","dependency-injection","go","reflection"],"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/4strodev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","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-09-30T13:39:58.000Z","updated_at":"2025-01-09T22:20:34.000Z","dependencies_parsed_at":"2024-11-02T13:18:39.445Z","dependency_job_id":"9d2cf5bc-1abf-4848-abd8-8910d0f465f5","html_url":"https://github.com/4strodev/wiring","commit_stats":null,"previous_names":["4strodev/wiring"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/4strodev%2Fwiring","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/4strodev%2Fwiring/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/4strodev%2Fwiring/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/4strodev%2Fwiring/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/4strodev","download_url":"https://codeload.github.com/4strodev/wiring/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":235951148,"owners_count":19071243,"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":["autowiring","container","dependency-injection","go","reflection"],"created_at":"2024-11-29T13:17:48.570Z","updated_at":"2025-10-10T12:30:53.483Z","avatar_url":"https://github.com/4strodev.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Deprecated\nIf anyone uses this library I have to tell you that is going to be deprecated. It lacks a set of basic functionalities\nand the implementation is not well designed. I started a new implementation [here](https://github.com/4strodev/wiring-graphs).\n\n[![go badge](https://pkg.go.dev/badge/github.com/4strodev/wiring.svg)](https://pkg.go.dev/github.com/4strodev/wiring)\n![lint status badge](https://github.com/4strodev/wiring/actions/workflows/lint.yaml/badge.svg)\n![test status badge](https://github.com/4strodev/wiring/actions/workflows/test.yaml/badge.svg)\n# 🔌 Wiring\nA container for DI and autowiring written in Go. The main purpose is to provide an interface and a default implementation\nfor autowiring. You can use the default implementation or create your own if the requirements of your project are not\nsatisfied.\n\n## Download\n\n    go get github.com/4strodev/wiring@latest\n    \n\n# 🌟 Features\nYet this library tries to be as simple as possible I tried to create the minimum features to cover the majority of usecases.\n\n## Lifecycle\nThere are two kind of lifecycles\n\n- **Singleton**: These dependencies are instantiated once and then the instance is cached for future resolves.\n  - The default implementation is **🧵 concurrently safe**.\n- **Transient**: Those are dependencies that are always instantiated every time they are resolved.\n- **Scoped**: For scoped dependencies take a look to the `extended` package.\n\n### Ej. Resolve a dependency\n```go\npackage main\n\nimport (\n    \t\"fmt\"\n    \twiring \"github.com/4strodev/wiring/pkg\"\n)\n\ntype Abstraction interface {\n    \tGreet()\n}\n\ntype Implementation struct {\n}\n\nfunc (i *Implementation) Greet() {\n    \tfmt.Println(\"Hello world\")\n}\n\nfunc main() {\n\tvar container = wiring.New()\n\tcontainer.Singleton(func() (Abstraction, error) {\n        \t// This resolver is executed just once\n\t\tfmt.Println(\"Running resolver\")\n\t\treturn \u0026Implementation{}, nil\n\t})\n\n    \t// Resolving dependency\n\tvar impl Abstraction\n\tcontainer.Resolve(\u0026impl)\n\timpl.Greet()\n\n\tvar otherImpl Abstraction\n\tcontainer.Resolve(\u0026otherImpl)\n\totherImpl.Greet()\n\t// Output:\n\t// Running resolver\n\t// Hello world\n\t// Hello world\n}\n```\n\n## Extended containers\nThe `extended` package contains extensions for containers:\n\n- **Derived**: A derived container allows you to create containers that inherits resolvers from parent containers. This is a fully functional container which can has their own and *Scoped 🚀* dependencies.\n  Allowing you to use container for short living contexts like an http request.\n- **Must**: An interface that instead of returning errors panics.\n\n## Token based\nToken based dependencies allows you to specify dependencies using a custom token. These are performant, because they are not relying in reflection (at all), and allows you to have\nmultiple dependencies of the same type but with different tokens.\n\n### Ej. Resolving a dependency\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\twiring \"github.com/4strodev/wiring/pkg\"\n)\n\ntype Abstraction interface {\n\tGreet()\n}\n\ntype Implementation struct {\n}\n\nfunc (i *Implementation) Greet() {\n\tfmt.Println(\"Hello world\")\n}\n\nfunc main() {\n\tvar container = wiring.New()\n\terr := container.TransientToken(\"abstraction\", func() (Abstraction, error) {\n\t\treturn \u0026Implementation{}, nil\n\t})\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tvar impl Abstraction\n\terr = container.ResolveToken(\"abstraction\", \u0026impl)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\timpl.Greet()\n}\n```\n\n## Struct filling\nDo you have massive dependencies? No problem define a struct with exported fields and let the container fill your struct with the dependencies you need.\n```go\npackage main\n\nimport (\n    \t\"fmt\"\n    \t\"log\"\n\n    \twiring \"github.com/4strodev/wiring/pkg\"\n)\n\ntype Abstraction interface {\n    \tGreet()\n}\n\ntype Implementation struct {\n}\n\nfunc (i *Implementation) Greet() {\n    \tfmt.Println(\"Hello world\")\n}\n\ntype FillableStruct struct {\n    \tGreeter         Abstraction // if no tag is specified it is resolved by type\n    \tTokenBased      Abstraction `wire:\"token\"`\n    \tIgnoredReader   io.Reader   `wire:\",ignore\"`\n    \tignoredField    string\n\n}\n\nfunc main() {\n\tvar container = wiring.New()\n\tcontainer.Singleton(func() (Abstraction, error) {\n        \t// This resolver is executed just once\n\t\treturn \u0026Implementation{}, nil\n\t})\n\n\tcontainer.SingletonToken(\"token\", func() (Abstraction, error) {\n        \t// This resolver is executed just once\n\t\treturn \u0026Implementation{}, nil\n\t})\n\n    \tvar fillable FillableStruct\n    \terr := container.Fill(\u0026fillable)\n    \tif err != nil {\n\t\tlog.Fatal(err)\n    \t}\n\n    \tfillable.Greeter.Greet()\n    \tfillable.TokenBased.Greet()\n}\n```\n\n## Docs\nThere are more examples on [the documentation](https://pkg.go.dev/github.com/4strodev/wiring)\n\n## Inspiration\nThis project was heavily inspired by [goloby/container](https://github.com/golobby/container).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F4strodev%2Fwiring","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F4strodev%2Fwiring","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F4strodev%2Fwiring/lists"}