{"id":31943602,"url":"https://github.com/dancecoder/di-service","last_synced_at":"2025-10-14T09:59:17.756Z","repository":{"id":42558020,"uuid":"510835836","full_name":"dancecoder/di-service","owner":"dancecoder","description":"Really simple dependency injection solution for JavaScript","archived":false,"fork":false,"pushed_at":"2023-05-25T13:14:19.000Z","size":55,"stargazers_count":2,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-23T16:47:03.160Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/dancecoder.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":"2022-07-05T17:36:35.000Z","updated_at":"2022-12-15T00:25:34.000Z","dependencies_parsed_at":"2023-01-25T12:31:06.860Z","dependency_job_id":null,"html_url":"https://github.com/dancecoder/di-service","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"purl":"pkg:github/dancecoder/di-service","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dancecoder%2Fdi-service","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dancecoder%2Fdi-service/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dancecoder%2Fdi-service/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dancecoder%2Fdi-service/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dancecoder","download_url":"https://codeload.github.com/dancecoder/di-service/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dancecoder%2Fdi-service/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279018558,"owners_count":26086405,"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","status":"online","status_checked_at":"2025-10-14T02:00:06.444Z","response_time":60,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":[],"created_at":"2025-10-14T09:59:13.570Z","updated_at":"2025-10-14T09:59:17.750Z","avatar_url":"https://github.com/dancecoder.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"![DI Service](di-service.svg)\n# DI Service\nReally simple dependency injection solution for JavaScript\n\n## Features\n* Implements DI pattern\n* Do not impose any system architecture, may be introduced to any JavaScript project (FE and BE both)\n* Pure JavaScript implementation (+ TypeScript declaration file) \n* Zero dependencies\n* ES Module and CommonJS hybrid module\n\n## Example\nDeclare any class\n```javascript\nclass Settings {\n    dbServer = process.ENV.DB_SERVER;\n    dbUser = process.ENV.DB_USER;\n    dbPassword = process.ENV.DB_PASSWORD; // don't do like this\n}\n\nmodule.exports = { Settings };\n```\n\nUse the class as a dependency\n```javascript\nconst { Settings } = require('./settings');\nconst { SERVICE_REQUIRE } = require('di-service');\n\nclass DBConnection {\n    \n    static [SERVICE_REQUIRE] = [Settings];\n    \n    constructor(settings) {        \n        // settings -\u003e instance of the Settings class\n        this.settings = settings;\n    }\n}\n\nmodule.exports = { DBConnection };\n```\n\nGet service instance\n```javascript\nconst { DIService } = require('di-service');\nconst { DBConnection } = require('./db-connection');\n\nconst services = new DIService();\nconst connection1 = await services.getInstance(DBConnection);\nconst connection2 = await services.getInstance(DBConnection);\nconsole.log(connection1 === connection2); // -\u003e true\nconsole.log(connection1.settings === connection2.settings); // -\u003e true\nconsole.log(connection1.settings.constructor.name); // -\u003e Settings\n```\n\n## Used by\n[\u003cimg src=\"https://avatars.githubusercontent.com/u/50610858?s=100\" width=\"100\" height=\"100\" /\u003e](https://bllink.co/en/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdancecoder%2Fdi-service","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdancecoder%2Fdi-service","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdancecoder%2Fdi-service/lists"}