injection-js
Advanced tools
Comparing version 1.0.0 to 1.0.1
{ | ||
"name": "injection-js", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Dependency Injection library for JavaScript and TypeScript", | ||
@@ -10,5 +10,2 @@ "main": "injection.bundle.js", | ||
"dependencies": {}, | ||
"peerDependencies": { | ||
"reflect-metadata": "^0.1.9" | ||
}, | ||
"keywords": [ | ||
@@ -15,0 +12,0 @@ "DI", |
# Dependency Injection | ||
Extraction of the Angular's Dependency Injection which allows you to use it outside of the framework. | ||
Dependency injection library for JavaScript and TypeScript in **6.6K**. It is extraction of the Angular's dependency injection which means that it's feature complete, reliable and well tested. | ||
# How to use? | ||
``` | ||
$ npm i injection-js --save | ||
``` | ||
Note that for ES5 `Class` syntax and TypeScript you need a polyfill for the [Reflect API](http://www.ecma-international.org/ecma-262/6.0/#sec-reflection). You can use, for instance, [reflect-metadata](https://www.npmjs.com/package/reflect-metadata), or [`core-js` (`core-js/es7/reflect`)](https://www.npmjs.com/package/core-js). | ||
## TypeScript | ||
@@ -25,3 +31,3 @@ | ||
injector.get(Service); | ||
console.log(injector.get(Service) instanceof Service); | ||
``` | ||
@@ -33,3 +39,3 @@ | ||
require('reflect-metadata'); | ||
var di = require('../dist'); | ||
var di = require('injection-js'); | ||
@@ -51,2 +57,24 @@ var Http = di.Class({ | ||
## ES6 | ||
```js | ||
const { Inject, ReflectiveInjector } = require('injection-js'); | ||
class Http {} | ||
class Service { | ||
static get parameters() { | ||
return [[new Inject(Http)]]; | ||
} | ||
constructor(http) { | ||
this.http = http; | ||
} | ||
} | ||
const injector = ReflectiveInjector.resolveAndCreate([Http, Service]); | ||
console.log(injector.get(Service) instanceof Service); | ||
``` | ||
For full documentation click [here](https://angular.io/docs/ts/latest/guide/dependency-injection.html). | ||
@@ -53,0 +81,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
283605
0
83