{"id":20302358,"url":"https://github.com/re-js/provi","last_synced_at":"2026-05-18T04:41:50.112Z","repository":{"id":57749820,"uuid":"524552476","full_name":"re-js/provi","owner":"re-js","description":"Minimalistic and cute Service Provider","archived":false,"fork":false,"pushed_at":"2023-12-01T14:17:05.000Z","size":203,"stargazers_count":1,"open_issues_count":6,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-15T14:50:02.678Z","etag":null,"topics":[],"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/re-js.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-08-14T02:15:50.000Z","updated_at":"2023-12-01T00:45:50.000Z","dependencies_parsed_at":"2024-11-14T16:34:59.628Z","dependency_job_id":"b328a1fc-261a-4c02-b9bd-e0c66a69c916","html_url":"https://github.com/re-js/provi","commit_stats":{"total_commits":17,"total_committers":1,"mean_commits":17.0,"dds":0.0,"last_synced_commit":"72937e2c2debacda86c7de7fd55bfff92f0bce6e"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/re-js%2Fprovi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/re-js%2Fprovi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/re-js%2Fprovi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/re-js%2Fprovi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/re-js","download_url":"https://codeload.github.com/re-js/provi/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241801194,"owners_count":20022383,"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-14T16:30:54.198Z","updated_at":"2026-05-18T04:41:50.084Z","avatar_url":"https://github.com/re-js.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# provi\n\n[![npm version](https://img.shields.io/npm/v/provi?style=flat-square)](https://www.npmjs.com/package/provi)\n[![npm bundle size](https://img.shields.io/bundlephobia/minzip/provi?style=flat-square)](https://bundlephobia.com/result?p=provi)\n[![code coverage](https://img.shields.io/coveralls/github/re-js/provi?style=flat-square)](https://coveralls.io/github/re-js/provi)\n[![typescript supported](https://img.shields.io/npm/types/typescript?style=flat-square)](index.d.ts)\n\nMinimalistic and cute Service Provider for server environment (node.js, bun) and for clients (browser, native).\n\n- You can use it at any place of your application without rewriting your application's architecture or other preparations or initializations.\n- Each dependency can be a class or function.\n- Feel free with your shared logic.\n\nThe **service provider** pattern - also called _service locator_ pattern.\n\nAdvantages over Dependency Injection:\n\n  - Zero configuration, easy to use everywhere whole your app.\n  - Start-time and run-time dependency resolving, solving the circular dependency problem.\n  - Smaller bundle size.\n\nnode.js or bun usage\n\n```javascript\nimport { provide } from \"provi/server\"\n\nclass Db { /* ... */ }\n\n// Define dependencies using \"provide\" function\nexport class App {\n  db = provide(Db)\n  // ...\n  start() {\n    this.db.init()\n    // ...\n  }\n}\n```\n\nbrowser or native usage\n\n```javascript\nimport { provide } from \"provi/client\"\n\nclass Auth {\n  // user = sharedUser()\n  // ...\n  logout() {\n    if (sharedUser().isAnonymous) return\n    // ...\n  }\n}\n\nexport const sharedAuth = () =\u003e provide(Auth)\n```\n\nin both ways you can use plain javascript functions as dependency constructor\n\n```javascript\nimport { provide } from \"provi/client\"\n\nconst User = () =\u003e {\n  // ...\n  return {\n    get isAnonymous() {\n      return true;\n    }\n  }\n}\n\nexport const sharedUser = () =\u003e provide(User)\n```\n\n**Isolation of async scopes** (only in node environment)\n\nRun your app in isolated Service Provider scope. All instances cached for this will be isolated from all cached instances in other scopes. Useful for implementing SSR.\n\n```javascript\nimport { isolate } from \"provi/ssr\"\n\nconst html = await isolate(async () =\u003e {\n  const { run } = provide(Logic); // Isolated instance of app logic\n  await run();\n  // ...\n  return ReactDOMServer.renderToString(\u003cApp /\u003e);\n});\n```\n\nEach isolated instance will be destroyed at the end of the isolated asynchronous function.\n\n\n**Installation**\n\n```bash\nnpm install provi\n```\n\nEnjoy your code!","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fre-js%2Fprovi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fre-js%2Fprovi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fre-js%2Fprovi/lists"}