{"id":17004829,"url":"https://github.com/clickermonkey/deps","last_synced_at":"2025-03-22T10:39:17.114Z","repository":{"id":64299205,"uuid":"567070598","full_name":"ClickerMonkey/deps","owner":"ClickerMonkey","description":"Dependency injection with Go and generics","archived":false,"fork":false,"pushed_at":"2023-04-04T02:26:05.000Z","size":45,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-01-27T10:23:10.187Z","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":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ClickerMonkey.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":"2022-11-17T02:10:31.000Z","updated_at":"2022-11-21T06:16:56.000Z","dependencies_parsed_at":"2024-06-20T17:19:18.789Z","dependency_job_id":"f83ec601-af28-46b3-8330-66a8592ed7e6","html_url":"https://github.com/ClickerMonkey/deps","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ClickerMonkey%2Fdeps","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ClickerMonkey%2Fdeps/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ClickerMonkey%2Fdeps/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ClickerMonkey%2Fdeps/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ClickerMonkey","download_url":"https://codeload.github.com/ClickerMonkey/deps/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244945597,"owners_count":20536295,"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-14T04:44:33.661Z","updated_at":"2025-03-22T10:39:17.095Z","avatar_url":"https://github.com/ClickerMonkey.png","language":"Go","readme":"# deps\nDependency injection with Go and generics. Featuring lazy loading, lifetime control, pointer usage detection, hierarchal scopes, resource freeing, dynamic providers, and dynamic types.\n\n\n```go\npackage main\n\nimport github.com/ClickerMonkey/deps\n\ntype Port int\ntype Env struct {\n  Connection string\n}\ntype Database struct {\n  Query func(sql string) []any\n}\ntype UserPreferences struct {\n  Name string\n}\ntype Path[V any] struct {\n  Value V\n}\n// Dynamic values, essential for generics\nfunc (p *Path[V]) ProvideDynamic(scope *Scope) error {\n  // populate p\n  return nil\n}\n\nfunc main() {\n  // Set values or provide functions\n  deps.Set(Port(8080))\n\n  // Globally provided value\n  deps.Provide(deps.Provider[Env]{\n    Create: func(scope *deps.Scope) (*Env, error) {\n      // TODO load environment values and return env\n      return \u0026Env{}, nil\n    },\n  })\n  // Value that lives on scope so it can be properly freed\n  deps.Provide(deps.Provider[Database]{\n    Lifetime: deps.LifetimeScope,\n    Create: func(scope *deps.Scope) (*Database, error) {\n      env, err := deps.GetScoped[Env](scope)\n      if err != nil {\n        return nil, err\n      }\n      // TODO create connection from env.Connection\n      return \u0026Database{}, nil\n    },\n    Free: func(scope *deps.Scope, db *Database) error {\n      // TODO close connection\n    },\n  })\n  // Value that exists globally but is notified when its potentially modified.\n  deps.Provide(deps.Provider[UserPreferences]{\n    Create: func(scope *deps.Scope) (*UserPreferences, error) {\n      return \u0026UserPreferences{Name: \"ClickerMonkey\"}, nil\n    },\n    AfterPointerUse: func(scope *deps.Scope, prefs *UserPreferences) error {\n      // save user preferences, a pointer was requested to change its state.\n      return nil\n    },\n  })\n\n  // Invoke global function\n  deps.Invoke(func(port Port, param Path[string]) {\n    // do stuff with port.\n    // param was dynamically created by an instance of its type, great for generics\n  })\n\n  // A child scope from Global\n  s := deps.New()\n  env, _ := deps.Get[Env]() // get env from global scope\n  db, _ := deps.GetScoped[Database](s) // gets database connection and stores it in this scope\n  s.Free() // free values in this scope\n\n  // Store a value directly on this scope\n  s.Set(\"Phil\") // newName below\n  // Also do a custom provider for this scope only\n  deps.ProvideScoped(s, deps.Provider[int]{\n    Create: func(scope *deps.Scope) (*int, error) {\n      age := 33\n      return \u0026age, nil\n    }\n  })\n\n  // Invoke a function and provide it with values from the scope.\n  s.Invoke(func(env Env, prefs *UserPreferences, newName string, age int) {\n    prefs.Name = newName // would trigger a notification above\n  })\n  \n  // We can also dynamically provide other values that are not set in the scope or its ancestors or\n  // are associated with any providers or implements deps.Dynamic.\n  s.DynamicProvider = func(typ reflect.Type, scope *Scope) (any, error) {\n    // generate value of typ if supported, otherwise return nil, nil\n    return nil, nil\n  }\n\n  // For good measure\n  deps.Global().Free()\n}\n\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclickermonkey%2Fdeps","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fclickermonkey%2Fdeps","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclickermonkey%2Fdeps/lists"}