{"id":41929178,"url":"https://github.com/eddieowens/axon","last_synced_at":"2026-01-25T17:35:47.076Z","repository":{"id":34536386,"uuid":"154222415","full_name":"eddieowens/axon","owner":"eddieowens","description":"A simple, lightweight, and lazy-loaded DI (really just a singleton management) library.","archived":false,"fork":false,"pushed_at":"2022-05-23T01:33:11.000Z","size":54,"stargazers_count":22,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-06-19T00:04:03.995Z","etag":null,"topics":["dependency-injection","generics","go","golang"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/eddieowens.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":"2018-10-22T21:53:50.000Z","updated_at":"2023-12-06T08:17:40.000Z","dependencies_parsed_at":"2022-08-28T11:51:47.813Z","dependency_job_id":null,"html_url":"https://github.com/eddieowens/axon","commit_stats":null,"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"purl":"pkg:github/eddieowens/axon","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eddieowens%2Faxon","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eddieowens%2Faxon/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eddieowens%2Faxon/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eddieowens%2Faxon/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eddieowens","download_url":"https://codeload.github.com/eddieowens/axon/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eddieowens%2Faxon/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28756011,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-25T16:32:25.380Z","status":"ssl_error","status_checked_at":"2026-01-25T16:32:09.189Z","response_time":113,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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","go","golang"],"created_at":"2026-01-25T17:35:46.369Z","updated_at":"2026-01-25T17:35:47.065Z","avatar_url":"https://github.com/eddieowens.png","language":"Go","funding_links":[],"categories":["Go"],"sub_categories":[],"readme":"# axon\n\n[![Go Report Card](https://goreportcard.com/badge/github.com/eddieowens/axon)](https://goreportcard.com/report/github.com/eddieowens/axon)\n[![License](https://img.shields.io/badge/License-Apache%202.0-yellowgreen.svg)](https://github.com/eddieowens/axon/blob/master/LICENSE)\n[![godoc](https://img.shields.io/badge/godoc-reference-blue)](https://pkg.go.dev/github.com/eddieowens/axon?tab=doc)\n\nA simple, lightweight, and lazy-loaded DI (really just a singleton management) library that supports generics.\nInfluenced by multiple DI\nlibraries but more specifically Google's [Guice](https://github.com/google/guice).\n\n## Install\n\n```bash\ngo get github.com/eddieowens/axon\n```\n\n## Usage\n\n### Basic\n\nSimple add and get with a string key\n\n```go\npackage main\n\nimport (\n  \"fmt\"\n  \"github.com/eddieowens/axon\"\n)\n\nfunc main() {\n  axon.Add(\"AnswerToTheUltimateQuestion\", 42)\n  answer := axon.MustGet(axon.WithKey(\"AnswerToTheUltimateQuestion\"))\n  fmt.Println(answer) // prints 42\n}\n\n```\n\nYou can also use a type as a key\n\n```go\npackage main\n\nimport (\n  \"fmt\"\n  \"github.com/eddieowens/axon\"\n)\n\nfunc main() {\n  axon.Add(axon.NewTypeKey[int](42))\n  answer := axon.MustGet[int]()\n  fmt.Println(answer) // prints 42\n}\n```\n\n### Injecting dependencies\n\nTo inject dependencies to a struct, you can use the `Inject` func.\n\n```go\npackage main\n\nimport (\n  \"fmt\"\n  \"github.com/eddieowens/axon\"\n)\n\ntype Struct struct {\n  Answer int `inject:\"AnswerToTheUltimateQuestion\"`\n}\n\nfunc main() {\n  axon.Add(\"AnswerToTheUltimateQuestion\", 42)\n\n  s := new(Struct)\n  _ = axon.Inject(s)\n  fmt.Println(s.Answer) // prints 42\n}\n```\n\nA more full fledged example\n\n```go\npackage main\n\nimport (\n  \"fmt\"\n  \"github.com/eddieowens/axon\"\n  \"os\"\n)\n\ntype DatabaseClient interface {\n  DeleteUser(user string) error\n}\n\ntype databaseClient struct {\n}\n\nfunc (d *databaseClient) DeleteUser(_ string) error {\n  fmt.Println(\"Deleting user!\")\n  return nil\n}\n\ntype ServerConfig struct {\n  Port int `inject:\"port\"`\n}\n\ntype Server struct {\n  // inject whatever is the default for the DBClient type\n  DB           DatabaseClient `inject:\",type\"`\n  ServerConfig ServerConfig   `inject:\"config\"`\n}\n\nfunc main() {\n  axon.Add(\"port\", os.Getenv(\"PORT\"))\n\n  // default implementation for DatabaseClient\n  axon.Add(axon.NewTypeKey[DatabaseClient](new(databaseClient)))\n\n  // construct the Config whenever it's needed (only ever called once)\n  axon.Add(\"config\", axon.NewFactory[ServerConfig](func(_ axon.Injector) (ServerConfig, error) {\n    return ServerConfig{}, nil\n  }))\n\n  s := new(Server)\n  _ = axon.Inject(s)\n  fmt.Println(s.ServerConfig.Port)     // prints value of env var PORT\n  fmt.Println(s.DB.DeleteUser(\"user\")) // prints Deleting user!\n}\n```\n\nFor more examples and info, check out the [GoDoc](https://pkg.go.dev/github.com/eddieowens/axon?tab=doc)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feddieowens%2Faxon","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feddieowens%2Faxon","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feddieowens%2Faxon/lists"}