{"id":18527131,"url":"https://github.com/ompluscator/genjector","last_synced_at":"2025-04-09T12:32:19.114Z","repository":{"id":61629367,"uuid":"551527474","full_name":"Ompluscator/genjector","owner":"Ompluscator","description":"Reflection-free Run-Time Dependency Injection framework for Go 1.18+","archived":false,"fork":false,"pushed_at":"2022-10-18T22:25:01.000Z","size":54,"stargazers_count":46,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-24T05:51:52.753Z","etag":null,"topics":[],"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/Ompluscator.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}},"created_at":"2022-10-14T15:12:09.000Z","updated_at":"2024-06-20T09:58:53.000Z","dependencies_parsed_at":"2023-01-20T09:00:16.483Z","dependency_job_id":null,"html_url":"https://github.com/Ompluscator/genjector","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ompluscator%2Fgenjector","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ompluscator%2Fgenjector/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ompluscator%2Fgenjector/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ompluscator%2Fgenjector/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Ompluscator","download_url":"https://codeload.github.com/Ompluscator/genjector/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248040710,"owners_count":21037924,"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-11-06T17:53:23.558Z","updated_at":"2025-04-09T12:32:17.955Z","avatar_url":"https://github.com/Ompluscator.png","language":"Go","readme":"[![Go Reference](https://pkg.go.dev/badge/github.com/Ompluscator/genjector.svg)](https://pkg.go.dev/github.com/Ompluscator/genjector)\n![Coverage](https://img.shields.io/badge/Coverage-97.8%25-brightgreen)\n[![Go Report Card](https://goreportcard.com/badge/github.com/ompluscator/genjector)](https://goreportcard.com/report/github.com/ompluscator/genjector)\n\n# Package Genjector\nReflection-free Run-Time Dependency Injection framework for Go 1.18+\n\nRead [blog](https://hindenbug.io/genjector-reflection-free-run-time-dependency-injection-framework-for-go-1-18-1022d134123d) for better examples!\n\n## The Goal\nThe purpose of The Genjector package is to provide a Dependency\nInjection framework without relying on reflection and depending solely\non Go Generics (provided from Go version 1.18).\n\nIt supports many different features:\n+ Binding concrete implementations to particular interfaces.\n+ Binding implementations as pointers or values.\n+ Binding implementations with Provider methods.\n+ Binding implementations with concrete instances.\n+ Define Binding as singletons.\n+ Define annotations for Binding.\n+ Define slices and maps of implementations.\n+ ...\n\n## Benchmark\nWhile providing the most of known features of Dependency Injection\nframeworks, The Genjector Package also delivers top performance\ncomparing to current widely used Run-Time DI frameworks, (so, solutions\nbased on code generators are excluded).\n\n```shell\ngoos: darwin\ngoarch: amd64\npkg: github.com/ompluscator/genjector/_benchmark\ncpu: Intel(R) Core(TM) i5-1038NG7 CPU @ 2.00GHz\nBenchmark\nBenchmark/github.com/golobby/container/v3\nBenchmark/github.com/golobby/container/v3-8         \t 2834061\t       409.6 ns/op\nBenchmark/github.com/goava/di\nBenchmark/github.com/goava/di-8                     \t 4568984\t       261.9 ns/op\nBenchmark/github.com/goioc/di\nBenchmark/github.com/goioc/di-8                     \t19844284\t        60.66 ns/op\nBenchmark/go.uber.org/dig\nBenchmark/go.uber.org/dig-8                         \t  755488\t      1497 ns/op\nBenchmark/flamingo.me/dingo\nBenchmark/flamingo.me/dingo-8                       \t 2373394\t       503.7 ns/op\nBenchmark/github.com/samber/do\nBenchmark/github.com/samber/do-8                    \t 3585386\t       336.0 ns/op\nBenchmark/github.com/ompluscator/genjector\nBenchmark/github.com/ompluscator/genjector-8        \t21460600\t        55.71 ns/op\nBenchmark/github.com/vardius/gocontainer\nBenchmark/github.com/vardius/gocontainer-8          \t60947049\t        20.25 ns/op\nBenchmark/github.com/go-kata/kinit\nBenchmark/github.com/go-kata/kinit-8                \t  733842\t      1451 ns/op\nBenchmark/github.com/Fs02/wire\nBenchmark/github.com/Fs02/wire-8                    \t25099182\t        47.43 ns/op\nPASS\n```\n\n## Examples\nDetailed examples can be found inside inner \"examples\" package.\n\nSome simple code blocks can be found bellow.\n\n### Simple Pointer\n```go\npackage example\n\ntype ServiceInterface interface {\n  String() string\n}\n\ntype Service struct {\n  value string\n}\n\nfunc (s *Service) Init() {\n  s.value = \"value provided inside the Service\"\n}\n\nfunc (s *Service) String() string {\n  return s.value\n}\n\nerr := genjector.Bind(genjector.AsPointer[ServiceInterface, *Service]())\nif err != nil {\n  return err\n}\n\ninstance, err := genjector.NewInstance[ServiceInterface]()\nif err != nil {\n  return err\n}\n\nvalue := instance.String()\nif value != \"value provided inside the Service\" {\n  return err\n}\n```\n\n### Complex Pointer\n```go\npackage example\n\ntype ServiceInterface interface {\n  String() string\n}\n\ntype Service struct {\n  value string\n}\n\nfunc (s *Service) Init() {\n  s.value = \"value provided inside the Service\"\n}\n\nfunc (s *Service) String() string {\n  return s.value\n}\n\nerr := genjector.Bind(\n  genjector.AsPointer[ServiceInterface, *Service](),\n  genjector.AsSingleton(),\n  genjector.WithAnnotation(\"service\")\n)\nif err != nil {\n  return err\n}\n\ninstance, err := genjector.NewInstance[ServiceInterface](\n  genjector.WithAnnotation(\"service\"),\n)\nif err != nil {\n  return err\n}\n\nvalue := instance.String()\nif value != \"value provided inside the Service\" {\n  return err\n}\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fompluscator%2Fgenjector","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fompluscator%2Fgenjector","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fompluscator%2Fgenjector/lists"}