{"id":34808124,"url":"https://github.com/marcelsud/melody-di","last_synced_at":"2026-04-26T07:34:05.517Z","repository":{"id":37939944,"uuid":"166042879","full_name":"marcelsud/melody-di","owner":"marcelsud","description":"A simple and portable dependency injection library.","archived":false,"fork":false,"pushed_at":"2022-06-17T00:13:39.000Z","size":244,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-04-26T07:34:03.142Z","etag":null,"topics":["container","dependency-injection","dip","ioc","solid","typescript"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/marcelsud.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":"2019-01-16T13:14:48.000Z","updated_at":"2024-04-25T11:53:09.000Z","dependencies_parsed_at":"2022-08-26T01:00:34.221Z","dependency_job_id":null,"html_url":"https://github.com/marcelsud/melody-di","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/marcelsud/melody-di","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcelsud%2Fmelody-di","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcelsud%2Fmelody-di/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcelsud%2Fmelody-di/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcelsud%2Fmelody-di/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/marcelsud","download_url":"https://codeload.github.com/marcelsud/melody-di/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcelsud%2Fmelody-di/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32289926,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-26T06:26:00.361Z","status":"ssl_error","status_checked_at":"2026-04-26T06:25:58.791Z","response_time":129,"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":["container","dependency-injection","dip","ioc","solid","typescript"],"created_at":"2025-12-25T12:09:48.751Z","updated_at":"2026-04-26T07:34:05.491Z","avatar_url":"https://github.com/marcelsud.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# Melody Dependency Injection\n\nA simple dependency injection Container for Javascript/Typescript.\n\n\n- ☑️ Easy to use\n- ☑️ Maintainable\n- ☑️ Portable\n\n---\n\n## 📜 How to install\n\nYou can use NPM or Yarn to install it\n\n```bash\nnpm install --save @marcelsud/melody-di\n```\n\nor\n\n```bash\nyarn add @marcelsud/melody-di\n```\n\n## 🔥 Usage\n\n### Adding and getting a dependency\n\nCreating a container and adding dependencies is pretty straightforward.\n\nFirst, create the container:\n\n```typescript\nimport { Container } from '@marcelsud/melody-di'\nconst container = new Container()\n```\n\nAfter that add some dependency into the container:\n\n```typescript\n\nclass CalculatorService {\n  sum(a: number, b: number): number {\n    return a + b;\n  }\n}\n\ncontainer.set('calculator_service', () =\u003e {\n  return new CalculatorService()\n})\n```\n\nThen, get it somewhere else:\n\n```typescript\nconst calculatorService = container.get\u003cCalculatorService\u003e('calculator_service')\nconsole.log(calculatorService.sum(10, 5)) // 15\n```\n\nIt can also be added as a promise\n\n```typescript\ncontainer.set('calculator_service', async (c: Container) =\u003e {\n  const somethingElse = await c.get\u003cPromise\u003cSomethingElse\u003e\u003e('something_else')\n  return new CalculatorService(somethingElse)\n})\n\n// 2000 years later...\n\nconst service = await container.get\u003cPromise\u003cCalculatorService\u003e\u003e('calculator_service')\nconsole.log(service.sum(20, 30)) // 50\n```\n\n### Adding a plain value into the container\n\nYou can add a static value into the container, such as a number, a string, or even an object:\n\n```typescript\ncontainer.set('some_config', 'SUPER_SECRET_INFORMATION')\ncontainer.set('some_important_ttl', 5000)\ncontainer.set('some_config_map', {\n  something: 'QWERTYUIOPASDFGHJKL'   \n})\n\n// Directly instantiating the object\ncontainer.set('calculator_service', new CalculatorService())\n```\n\n## 🟢 Running the tests\n\nTo run the tets:\n\n```bash\n  npm t\n```\n\nor\n\n```bash\n  yarn test\n```\n\n\n## 🚀 About the author\n\nI am a passionate Principal Software Engineer. Amongst my favorite topics are Clean Architecture, Domain-Driven Design and Event-Driven Architecture. \n\nYou can find me out on:\n\n- \u003ca href=\"https://www.linkedin.com/in/marcelsud/\" target=\"_blank\"\u003e\u003cimg src=\"https://img.shields.io/badge/LinkedIn-0077B5?style=for-the-badge\u0026logo=linkedin\u0026logoColor=white\" /\u003e\u003c/a\u003e\n- \u003ca href=\"https://twitter.com/marcelsud\" target=\"_blank\"\u003e\u003cimg src=\"https://img.shields.io/badge/Twitter-1DA1F2?style=for-the-badge\u0026logo=twitter\u0026logoColor=white\" /\u003e\u003c/a\u003e\n\n\n## 📝 License\n\n[MIT](https://choosealicense.com/licenses/mit/)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarcelsud%2Fmelody-di","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarcelsud%2Fmelody-di","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarcelsud%2Fmelody-di/lists"}