Giter VIP home page Giter VIP logo

inversify-basic-example's Introduction

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)

inversify-basic-example's People

Contributors

bwheel181 avatar dcavanagh avatar dlarner3194 avatar greenkeeper[bot] avatar greenkeeperio-bot avatar johnjacobkenny avatar lholznagel avatar pitamar avatar remojansen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

inversify-basic-example's Issues

An in-range update of typescript is breaking the build 🚨

Version 2.3.3 of typescript just got published.

Branch Build failing 🚨
Dependency typescript
Current Version 2.3.2
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

As typescript is β€œonly” a devDependency of this project it might not break production or downstream projects, but β€œonly” your build or test tools – preventing new deploys or publishes.

I recommend you give this issue a high priority. I’m sure you can resolve this πŸ’ͺ

Status Details
  • ❌ continuous-integration/travis-ci/push The Travis CI build failed Details

Release Notes TypeScript 2.3.3

This release include a set of bug fixes reported against TypeScript 2.3.2. For the complete list of fixed issues, check out the fixed issues query for TypeScript 2.3.3.

Download:

Commits

The new version differs by 84 commits.

There are 84 commits in total.

See the full diff

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

An in-range update of tslint is breaking the build 🚨

Version 5.3.0 of tslint just got published.

Branch Build failing 🚨
Dependency tslint
Current Version 5.2.0
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

As tslint is β€œonly” a devDependency of this project it might not break production or downstream projects, but β€œonly” your build or test tools – preventing new deploys or publishes.

I recommend you give this issue a high priority. I’m sure you can resolve this πŸ’ͺ

Status Details
  • ❌ continuous-integration/travis-ci/push The Travis CI build failed Details

Release Notes v5.3.0

This change may require a change to tslint.json

πŸŽ‰ Notable features & enhancements

Thanks to our contributors!

  • Andy Hanson
  • Klaus Meinhardt
  • Martin Probst
  • Filipe Silva
  • walkerburgin
  • RenΓ© Scheibe
Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

An in-range update of tslint is breaking the build 🚨

Version 4.3.0 of tslint just got published.

Branch Build failing 🚨
Dependency tslint
Current Version 4.2.0
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

As tslint is β€œonly” a devDependency of this project it might not break production or downstream projects, but β€œonly” your build or test tools – preventing new deploys or publishes.

I recommend you give this issue a high priority. I’m sure you can resolve this πŸ’ͺ


Status Details
  • ❌ continuous-integration/travis-ci/push The Travis CI build failed Details
Release Notes v4.3.0
  • Enabled additional rules in tslint:latest configuration (#1981)
  • [new-rule] space-before-function-paren (#1897)
  • [new-rule] typeof-compare (#1927)
  • [new-rule] import-spacing (#1935)
  • [new-rule] unified-signatures (#1944)
  • [new-fixer] object-literal-key-quotes (#1953)
  • [new-fixer] no-angle-bracket-type-assertion (#1979)
  • [bugfix] adjacent-overload-signature now handles static/computed function names (#1831)
  • [bugfix] file-header now handles files with only comments (#1913)
  • [bugfix] no-consecutive-blank-lines now allows blank lines in template strings (#1886)
  • [bugfix] object-literal-key-quotes no longer throws exception when using rest operator (#1916)
  • [bugfix] restrict-plus-operands no longer shows false positive in ternary operation (#1925)
  • [bugfix] prefer-for-of now handles nested for loops with reused iterator (#1926)
  • [bugfix] Exit gracefully when tsconfig.json passed as --project argument doens't have files (#1933)
  • [bugfix] object-literal-key-quotes now handles shorthand and spread properties (#1945)
  • [bugfix] arrow-parens Allow binding patterns ([x, y]) => ... and ({x, y}) => ... to have parens (#1958)
  • [bugfix] semicolon fixer now handles comma separator in interfaces and indicates failure when commas are using in interfaces (#1856)
  • [bugfix] only-arrow-functions option allow-named-functions now allows function declarations (#1961)
  • [bugfix] prefer-for-of no longer shows false positive when array is in parentheses (#1986)
  • [bugfix] prefer-const now works for TypeScript versions < 2.1.0 (#1989)
  • [enhancement] member-access narrow location of error (#1964)

Thanks to our contributors!

  • Andrii Dieiev
  • @andy-ms
  • Andy Hanson
  • Josh Goldberg
  • Klaus Meinhardt
  • Linda_pp
  • Mohsen Azimi
  • Victor Grigoriu
  • Yuichi Nukiyama
  • cameron-mcateer
Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

reflect-metadata 0.1.9 triggers "read only property" TypeError

Compiling with 0.1.9 of reflect-metadata causes the following exception:

D:\Repos\inversify-basic-example\node_modules\inversify\lib\resolution\instantiation.js:14
        instance[propertyName] = injection;
                               ^
TypeError: Cannot assign to read only property 'warrior1' of object '#<EpicBattle>'

Downgrading to 0.1.8 corrects the issue.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.