GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - icsahn/inversify-basic-example: A basic example that showcases how to setup InversifyJS

BranchesTags
Open more actions menu
 
 

Latest commit

 

History

118 Commits
118 Commits

Folders and files

NameName
Last commit message
Last commit date
.vscode
.vscode
 
 
src
src
 
 
.gitignore
.gitignore
 
 
.travis.yml
.travis.yml
 
 
CODE_OF_CONDUCT.md
CODE_OF_CONDUCT.md
 
 
CONTRIBUTING.md
CONTRIBUTING.md
 
 
ISSUE_TEMPLATE.md
ISSUE_TEMPLATE.md
 
 
LICENSE
LICENSE
 
 
PULL_REQUEST_TEMPLATE.md
PULL_REQUEST_TEMPLATE.md
 
 
README.md
README.md
 
 
gulpfile.js
gulpfile.js
 
 
package.json
package.json
 
 
tsconfig.json
tsconfig.json
 
 
tslint.json
tslint.json
 
 
uml.png
uml.png
 
 

Repository files navigation

inversify-basic-example

Join the chat at https://gitter.im/inversify/inversify-basic-example Build Status Dependencies img img

A basic example that showcases how to setup InversifyJS

This is a very basic InversifyJS example.

This program declares:

  • Three interfaces Warrior, Weapon and Battle.
  • Two implementations of Weapon: Katana and Shuriken
  • Two implementations of Warrior: Ninja and Samurai
  • One implementation of Battle: EpicBattle.

The warriors own a weapon and are tagged with some metadata.

We use some constraints whenTargetNamed and whenParentNamed to indicate which Weapon should be injected into and implementation of Warrior and which implementation of Warrior should injected into EpicBattle:

container.bind<Warrior>(SERVICE_IDENTIFIER.WARRIOR).to(Ninja).whenTargetNamed(TAG.CHINESE);
container.bind<Warrior>(SERVICE_IDENTIFIER.WARRIOR).to(Samurai).whenTargetNamed(TAG.JAPANESE);
container.bind<Weapon>(SERVICE_IDENTIFIER.WEAPON).to(Shuriken).whenParentNamed(TAG.CHINESE);
container.bind<Weapon>(SERVICE_IDENTIFIER.WEAPON).to(Katana).whenParentNamed(TAG.JAPANESE);
container.bind<Battle>(SERVICE_IDENTIFIER.BATTLE).to(EpicBattle);

How can I run it?

You can clone it using:

$ git clone https://github.com/inversify/inversify-basic-example.git

To run this example you need to install some dependencies:

$ cd inversify-basic-example
$ npm install

And compile the TypeScript code into JavaScript code:

$ gulp

The generated code is available at the dist directory.

At this point you are ready to run the example:

$ node dist/main.js

You should see the following in console:

FIGHT!
                Ninja (Shuriken)
                vs
                Samurai (Katana)

About

A basic example that showcases how to setup InversifyJS

Resources

Readme
MIT license

Code of conduct

Code of conduct

Contributing

Contributing
Activity

Stars

0 stars

Watchers

1 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.