{"id":21855073,"url":"https://github.com/wix-incubator/obsidian","last_synced_at":"2026-05-03T09:04:49.402Z","repository":{"id":38020039,"uuid":"425408749","full_name":"wix-incubator/obsidian","owner":"wix-incubator","description":"Dependency injection library for React and React Native applications","archived":false,"fork":false,"pushed_at":"2025-03-23T06:14:12.000Z","size":9910,"stargazers_count":122,"open_issues_count":14,"forks_count":2,"subscribers_count":46,"default_branch":"master","last_synced_at":"2025-03-24T22:34:36.547Z","etag":null,"topics":["dagger","dagger-hilt","dependency-injection","dependency-inversion","hilt","ioc","ioc-container","react","react-native","swc","typescript"],"latest_commit_sha":null,"homepage":"https://wix-incubator.github.io/obsidian/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wix-incubator.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":"2021-11-07T04:05:31.000Z","updated_at":"2025-03-23T06:13:01.000Z","dependencies_parsed_at":"2023-02-18T22:15:57.209Z","dependency_job_id":"e6d6e0c7-5a0c-4f04-88dd-c8f9794b5b68","html_url":"https://github.com/wix-incubator/obsidian","commit_stats":null,"previous_names":["wix-incubator/react-obsidian"],"tags_count":40,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wix-incubator%2Fobsidian","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wix-incubator%2Fobsidian/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wix-incubator%2Fobsidian/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wix-incubator%2Fobsidian/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wix-incubator","download_url":"https://codeload.github.com/wix-incubator/obsidian/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247657275,"owners_count":20974344,"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":["dagger","dagger-hilt","dependency-injection","dependency-inversion","hilt","ioc","ioc-container","react","react-native","swc","typescript"],"created_at":"2024-11-28T02:13:20.542Z","updated_at":"2026-01-05T12:10:15.998Z","avatar_url":"https://github.com/wix-incubator.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![SWUbanner](https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/banner2-direct.svg)](https://vshymanskyy.github.io/StandWithUkraine)\n\n\u003cp align=\"center\"\u003e\n  \u003c/br\u003e\u003cimg width=\"300px\" src=\".github/logo.svg\"\u003e\u003c/br\u003e\u003c/br\u003e\n    \u003ca href=\"https://npmjs.com/package/react-obsidian\"\u003e\u003cimg src=\"https://raw.githubusercontent.com/wix-incubator/obsidian/gh-pages/badges/coverage-jest%20coverage.svg\" alt=\"coverage\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://www.npmjs.com/package/react-obsidian\"\u003e\u003cimg src=\"https://img.shields.io/npm/dm/react-obsidian.svg\" alt=\"NPM downloads\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://github.com/wix-incubator/react-obsidian/actions/workflows/ci.yml\"\u003e\u003cimg src=\"https://github.com/wix-incubator/react-obsidian/actions/workflows/ci.yml/badge.svg?branch=master\" alt=\"build status\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://discord.gg/MDH2axwaPy\"\u003e\u003cimg src=\"https://img.shields.io/badge/chat-discord-blue?style=flat\u0026logo=discord\" alt=\"discord chat\"\u003e\u003c/a\u003e\n    \u003c/br\u003e\n    \u003ca href=\"https://npmjs.com/package/react-obsidian\"\u003e\u003cimg src=\"https://img.shields.io/npm/v/react-obsidian.svg\" alt=\"npm package\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://github.com/wix-incubator/obsidian/pull/175\"\u003e\u003cimg src=\"https://img.shields.io/npm/v/react-obsidian/next.svg\" alt=\"npm package\"\u003e\u003c/a\u003e\n    \u003ch1 align=\"center\"\u003eObsidian\u003c/h1\u003e\n\u003c/p\u003e\n\nReact Obsidian is a dependency injection framework for React and React Native applications. It allows you to inject dependencies into hooks, components, and classes. Separating the construction and consumption of dependencies is crucial to maintaining a readable and testable codebase.\n\n\u003e 📖 Read more about Dependency Injection and Obsidian in [Breaking complexity with Dependency Injection: Introducing Obsidian](https://guyca.medium.com/breaking-complexity-with-dependency-injection-introducing-obsidian-cd452802f076) on Medium.\n\n* [Documentation](https://wix-incubator.github.io/obsidian/docs/documentation)\n  * [Getting Started](https://wix-incubator.github.io/obsidian/docs/documentation/#the-2-steps-tutorial-for-injecting-dependencies-with-obsidian)\n  * [Installation](https://wix-incubator.github.io/obsidian/docs/documentation/installation)\n  * [Guides](https://wix-incubator.github.io/obsidian/docs/guides/mockDependencies)\n* [Chat on Discord](https://discord.gg/MDH2axwaPy)\n\n## Example - Injecting a hook\nObsidian supports injecting hooks, components and classes. The example below shows how to inject a hook.\n\n### Step 1: Declare an object graph\nBefore we can inject dependencies into hooks, components and classes, we first need to declare our dependencies. Dependencies are declared in classes called \"Graphs\" where the relationships between the dependencies are outlined.\n\nIn the `ApplicationGraph` below, we declare two dependencies:\n1. `httpClient`\n2. `biLogger`\n\nBoth functions are annotated by the `@Provides()` annotation. This signals Obsidian that the results of these functions are provided by the graph and can be injected.\n\nNotice how the `biLogger` function receives an `httpClient` as an argument. This means that `biLogger` is dependent on `httpClient`. Obsidian will create an `httpClient` when `biLogger` is injected. \n\n``` typescript\n@singleton() @graph()\nclass ApplicationGraph extends ObjectGraph {\n  @provides()\n  httpClient(): HttpClient {\n    return new HttpClient();\n  }\n\n  @provides()\n  biLogger(httpClient: HttpClient): BiLogger {\n    return new BiLogger(httpClient);\n  }\n}\n```\n\n### Step 2: Inject a dependency\n\n```typescript\ntype Injected = DependenciesOf\u003cApplicationGraph, 'biLogger'\u003e; // { biLogger: BiLogger }\n\ninterface UseButtonPress {\n  usePress: () =\u003e void;\n}\n\n// We must use destructuring for Obsidian to be able to inject the dependencies\nconst useButtonClick = ({ biLogger }: Injected): UseButtonPress =\u003e {\n  const onClick = useCallback(() =\u003e {\n    biLogger.logButtonClick();\n  }, [biLogger]);\n  \n  return { onClick };\n};\n\n// Export the injected hook\nexport default injectHook(useButtonClick, ApplicationGraph);\n```\n\n### Step 3: Use the injected hook\nNow that we exported the injected hook, we can use it in a component without needing to provide its dependencies manually.\n\n```tsx\nconst Component = () =\u003e (\n  // No need to specify dependencies as they are injected automatically\n  const { onClick } = useButtonClick();\n  \u003c\u003e\n    \u003cbutton onclick={onClick}\u003eClick Me\u003c/button\u003e\n  \u003c/\u003e\n);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwix-incubator%2Fobsidian","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwix-incubator%2Fobsidian","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwix-incubator%2Fobsidian/lists"}