Environment support and polyfills

InversifyJS requires a modern JavaScript engine with support for the Promise, Map, Metadata Reflection API and Proxy objects. If your environment doesn't support one of these you will need to import a shim or polyfill.

Metadata Reflection API

:warning: The reflect-metadata polyfill should be imported only once in your entire application because the Reflect object is mean to be a global singleton. More details about this can be found here.

Required always. Use reflect-metadata as polyfill.

$ npm install reflect-metadata

The type definitions for reflect-metadata are included in the npm package. You need to add the following reference to the types field in your tsconfig.json:

"types": ["reflect-metadata"]

Finally, import reflect-metadata. If you are working in Node.js you can use:

import "reflect-metadata";

If you are working in a web browser you can use a script tag:

<script src="./node_modules/reflect-metadata/Reflect.js"></script>

This will create the Reflect object as a global.

Map

Maps are required when using InversifyJS 3 or higher.

Most modern JavaScript engines support map but if you need to support old browsers you will need to use a map polyfill (e.g. es6-map).

Promise

Promises are required only if you want to inject a provider.

Most modern JavaScript engines support promises but if you need to support old browsers you will need to use a promise polyfill (e.g. es6-promise or bluebird).

Proxy

Proxies are required only if you want to inject a proxy.

As today (September 2016) proxies are not very well supported and it is very likely that you will need to use a proxy polyfill. For example, we use harmony-proxy as polyfill to run our unit tests.

results matching ""

    No results matching ""