{"id":20340904,"url":"https://github.com/leancodepl/spyglass","last_synced_at":"2025-04-11T23:31:05.519Z","repository":{"id":233864529,"uuid":"684062045","full_name":"leancodepl/spyglass","owner":"leancodepl","description":"Dependency injection POC","archived":false,"fork":false,"pushed_at":"2024-06-30T18:03:09.000Z","size":376,"stargazers_count":12,"open_issues_count":3,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-25T19:21:16.024Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Dart","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/leancodepl.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2023-08-28T11:28:51.000Z","updated_at":"2024-07-08T06:18:41.000Z","dependencies_parsed_at":null,"dependency_job_id":"73b63c16-5680-406d-aece-49e2aff092b8","html_url":"https://github.com/leancodepl/spyglass","commit_stats":null,"previous_names":["leancodepl/spyglass"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leancodepl%2Fspyglass","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leancodepl%2Fspyglass/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leancodepl%2Fspyglass/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leancodepl%2Fspyglass/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/leancodepl","download_url":"https://codeload.github.com/leancodepl/spyglass/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248494779,"owners_count":21113497,"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-14T21:24:36.866Z","updated_at":"2025-04-11T23:31:05.476Z","avatar_url":"https://github.com/leancodepl.png","language":"Dart","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Spyglass [WIP]\n\n\u003e Note: This package is in active development and its API might change\n\u003e frequently. Currently it's basically functional but might contain frequent\n\u003e bugs. It has not yet been thoroughly tested and is missing documentation and\n\u003e examples.\n\nReliable service locator for all your Dart needs.\n\n## Installation \u0026 usage\n\nAdd the latest `spyglass` to your pubspec and you're ready to go!\n\n```sh\ndart pub add spyglass\n```\n\nA basic hello world:\n\n```dart\nimport 'package:spyglass/spyglass.dart';\n\nvoid main() {\n  deps.add(Dependency.value(Greeter()));\n\n  final greeter = deps.get\u003cGreeter\u003e();\n\n  greeter.greet();\n}\n\nclass Greeter {\n  void greet() {\n    print('Hello world!');\n  }\n}\n```\n\nRegister dependencies:\n\n```dart\n// simplest way\ndeps.add(Dependency.value(SomeService()));\n\n// lazy\ndeps.add(Dependency(create: (deps) =\u003e SomeService()));\n\n// with dispose function\ndeps.add(\n  Dependency(\n    create: (deps) =\u003e SomeService(),\n    dispose: (service) =\u003e service.dispose(),\n  ),\n);\n\n// with another dependency as parameter\ndeps.add(\n  Dependency(\n    create: (deps) =\u003e SomeService(\n      other: deps.get\u003cSomeOtherService\u003e(),\n    ),\n  ),\n);\n\n// live updates on change\ndeps.add(\n  Dependency(\n    create: (deps) =\u003e SomeService(\n      other: deps.get\u003cSomeOtherService\u003e(),\n    ),\n    when: (deps) =\u003e deps.watch\u003cSomeOtherService\u003e(),\n    update: (deps, service) {\n      return service..other = deps.get\u003cSomeOtherService\u003e();\n    },\n  ),\n);\n\n// async initialization\ndeps.add(\n  Dependency(\n    create: (deps) async {\n      final service = SomeService();\n      await service.ensureInitialized();\n      return service;\n    },\n  ),\n);\n\n// await other dependencies\ndeps.add(\n  Dependency(\n    create: (deps) async {\n      final other = deps.getAsync\u003cSomeOtherService\u003e();\n      return SomeService(\n        other: other,\n      );\n    },\n  ),\n);\n```\n\nRead \u0026 watch changes:\n\n```dart\n// sync\nSomeService service = deps.get\u003cSomeService\u003e();\n\n// optional\nSomeService? service = deps.tryGet\u003cSomeService\u003e();\n\n// asynchronously initialized\nSomeService service = await deps.getAsync\u003cSomeService\u003e();\n\n// watch updates\nStream\u003cSomeService\u003e serviceStream = deps.watch\u003cSomeService\u003e();\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleancodepl%2Fspyglass","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fleancodepl%2Fspyglass","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleancodepl%2Fspyglass/lists"}