{"id":24091408,"url":"https://github.com/dc0d/dion","last_synced_at":"2026-05-09T23:55:17.074Z","repository":{"id":269430819,"uuid":"905959088","full_name":"dc0d/dion","owner":"dc0d","description":"dion is a simple yet powerful DI container","archived":false,"fork":false,"pushed_at":"2025-01-04T10:25:48.000Z","size":30,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-04T11:34:42.197Z","etag":null,"topics":["deno","dependency-injection","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/dc0d.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":"2024-12-19T21:25:15.000Z","updated_at":"2025-01-04T10:25:51.000Z","dependencies_parsed_at":null,"dependency_job_id":"9e827a4c-080b-4ba4-9e7a-ac9f6bb15abc","html_url":"https://github.com/dc0d/dion","commit_stats":null,"previous_names":["dc0d/dion"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dc0d%2Fdion","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dc0d%2Fdion/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dc0d%2Fdion/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dc0d%2Fdion/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dc0d","download_url":"https://codeload.github.com/dc0d/dion/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240993951,"owners_count":19890419,"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":["deno","dependency-injection","typescript"],"created_at":"2025-01-10T07:43:58.539Z","updated_at":"2026-05-09T23:55:17.020Z","avatar_url":"https://github.com/dc0d.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n![GitHub top language](https://img.shields.io/github/languages/top/dc0d/dion)\n[![JSR](https://jsr.io/badges/@dc0d/dion)](https://jsr.io/@dc0d/dion)\n[![JSR Score](https://jsr.io/badges/@dc0d/dion/score)](https://jsr.io/@dc0d/dion)\n[![stability-alpha](https://img.shields.io/badge/stability-alpha-f4d03f.svg)](https://github.com/mkenney/software-guides/blob/master/STABILITY-BADGES.md#alpha)\n\n# dion\n\n`dion` is a simple DI container - at this stage, a playground for trying out an idea.\n\n## example web api\n\nAn example Git repository can be found [here](https://github.com/dc0d/dion-example).\n\n## how to use\n\nThis module provides a simple single-file dependency injection system.\nIt allows you to register classes as injectable and inject them later as dependencies.\nThe classes can be registered with tags and/or groups.\nThe tags are used to inject a single class, while the groups are used to inject multiple classes.\nThe classes can be singletons or not.\n\nThere is this DI pattern used in JavaScript code-bases which injects some default dependencies,\nwhile allowing the user to override them with custom dependencies - for example during unit testing.\n\n```javascript\nimport { firstDependency } from \"./first-dependency.js\";\nimport { secondDependency } from \"./second-dependency.js\";\n\nconst defaultDependencies = {\n  firstDependency,\n  secondDependency,\n};\n\nexport class Example {\n  constructor(dependencies = defaultDependencies) {\n    this.firstDependency = dependencies.firstDependency;\n    this.secondDependency = dependencies.secondDependency;\n  }\n}\n```\n\nThe dion module provides a similar way for DI. For example you can register the default dependencies:\n\n```typescript\n// first_dependency.ts\nimport { injectable } from \"@dc0d/dion\";\nimport { Service } from \"./domain.ts\";\n\n@injectable({ tags: \"first_dependency\" })\nexport class FirstDependency implements Service {\n  public get(): string {\n    return \"FirstDependency\";\n  }\n}\n```\n\n```typescript\n// second_dependency.ts\nimport { injectable } from \"@dc0d/dion\";\nimport { Service } from \"./domain.ts\";\n\n@injectable({ tags: \"second_dependency\" })\nexport class SecondDependency implements Service {\n  public get(): string {\n    return \"SecondDependency\";\n  }\n}\n```\n\nAnd then inject them in the Example class:\n\n```typescript\nimport { inject } from \"@dc0d/dion\";\nimport { Service } from \"./domain.ts\";\n\nexport class Example {\n  #firstDependency: Service;\n  #secondDependency: Service;\n\n  constructor(\n    firstDependency = inject\u003cService\u003e({ tag: \"first_dependency\" }),\n    secondDependency = inject\u003cService\u003e({ tag: \"second_dependency\" }),\n  ) {\n    this.#firstDependency = firstDependency;\n    this.#secondDependency = secondDependency;\n  }\n\n  public run(): void {\n    console.log(this.#firstDependency.get());\n    console.log(this.#secondDependency.get());\n  }\n}\n```\n\nThe upside is the `Example` class has no knowledge of the actual implementations for `FirstDependency` or `SecondDependency` classes - unlike the JavaScript version - and depends only on the interface `Service` which they implement.\n\n# TODO\n\n- Better README.\n- Put the sample application in a separate git repository.\n- Creat GitHub workflows for publishing to `jsr`.\n- Fix `@moduledoc` - or move examples to READMS.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdc0d%2Fdion","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdc0d%2Fdion","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdc0d%2Fdion/lists"}