{"id":13981114,"url":"https://github.com/inversify/inversify-basic-example","last_synced_at":"2025-07-21T21:31:08.822Z","repository":{"id":66162937,"uuid":"67171307","full_name":"inversify/inversify-basic-example","owner":"inversify","description":"A basic example that showcases how to setup InversifyJS","archived":false,"fork":false,"pushed_at":"2020-05-25T16:18:53.000Z","size":260,"stargazers_count":110,"open_issues_count":2,"forks_count":207,"subscribers_count":13,"default_branch":"master","last_synced_at":"2025-06-06T21:14:28.962Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/inversify.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2016-09-01T22:38:47.000Z","updated_at":"2025-04-25T10:18:21.000Z","dependencies_parsed_at":"2024-01-13T10:42:51.719Z","dependency_job_id":"2009b40e-b3cf-4b21-9f8a-6d82de25d550","html_url":"https://github.com/inversify/inversify-basic-example","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/inversify/inversify-basic-example","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inversify%2Finversify-basic-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inversify%2Finversify-basic-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inversify%2Finversify-basic-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inversify%2Finversify-basic-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/inversify","download_url":"https://codeload.github.com/inversify/inversify-basic-example/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inversify%2Finversify-basic-example/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266381911,"owners_count":23920591,"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-07-21T11:47:31.412Z","response_time":64,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"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":"2024-08-09T04:02:02.224Z","updated_at":"2025-07-21T21:31:08.558Z","avatar_url":"https://github.com/inversify.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# inversify-basic-example\n[![Join the chat at https://gitter.im/inversify/inversify-basic-example](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/inversify/InversifyJS)\n[![Build Status](https://secure.travis-ci.org/inversify/inversify-basic-example.svg?branch=master)](https://travis-ci.org/inversify/inversify-basic-example)\n[![Dependencies](https://david-dm.org/inversify/inversify-basic-example.svg)](https://david-dm.org/inversify/inversify-basic-example#info=dependencies)\n[![img](https://david-dm.org/inversify/inversify-basic-example/dev-status.svg)](https://david-dm.org/inversify/inversify-basic-example/#info=devDependencies)\n[![img](https://david-dm.org/inversify/inversify-basic-example/peer-status.svg)](https://david-dm.org/inversify/inversify-basic-example/#info=peerDependenciess)\n\nA basic example that showcases how to setup InversifyJS\n\nThis is a very basic InversifyJS example. \n\nThis program declares: \n- Three interfaces `Warrior`, `Weapon` and `Battle`.\n- Two implementations of `Weapon`: `Katana` and `Shuriken`\n- Two implementations of `Warrior`: `Ninja` and `Samurai`\n- One implementation of `Battle`: `EpicBattle`.\n\nThe warriors own a weapon and are tagged with some metadata.\n\n![](uml.png)\n\nWe use some constraints `whenTargetNamed` and `whenParentNamed` to indicate which\n`Weapon` should be injected into and implementation of `Warrior` and which implementation\nof `Warrior` should injected into `EpicBattle`:\n\n```ts\ncontainer.bind\u003cWarrior\u003e(SERVICE_IDENTIFIER.WARRIOR).to(Ninja).whenTargetNamed(TAG.CHINESE);\ncontainer.bind\u003cWarrior\u003e(SERVICE_IDENTIFIER.WARRIOR).to(Samurai).whenTargetNamed(TAG.JAPANESE);\ncontainer.bind\u003cWeapon\u003e(SERVICE_IDENTIFIER.WEAPON).to(Shuriken).whenParentNamed(TAG.CHINESE);\ncontainer.bind\u003cWeapon\u003e(SERVICE_IDENTIFIER.WEAPON).to(Katana).whenParentNamed(TAG.JAPANESE);\ncontainer.bind\u003cBattle\u003e(SERVICE_IDENTIFIER.BATTLE).to(EpicBattle);\n```\n\n# How can I run it?\nYou can clone it using:\n\n```\n$ git clone https://github.com/inversify/inversify-basic-example.git\n```\n\nTo run this example you need to install some dependencies:\n\n```\n$ cd inversify-basic-example\n$ npm install\n```\n\nAnd compile the TypeScript code into JavaScript code:\n\n```\n$ gulp\n```\n\nThe generated code is available at the `dist` directory.\n\nAt this point you are ready to run the example:\n\n```\n$ node dist/main.js\n```\n\nYou should see the following in console:\n\n```\nFIGHT!\n                Ninja (Shuriken)\n                vs\n                Samurai (Katana)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finversify%2Finversify-basic-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Finversify%2Finversify-basic-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finversify%2Finversify-basic-example/lists"}