inversify / InversifyJS

A powerful and lightweight inversion of control container for JavaScript & Node.js apps powered by TypeScript.
http://inversify.io/
MIT License
11.33k stars 718 forks source link

Issue exporting/importing Container object #453

Closed basickarl closed 7 years ago

basickarl commented 7 years ago

I can't seem to export the Container object I made, it becomes undefined.

src/di/di_inversify.js:

'use strict';
import { Container, decorate, injectable, inject } from 'inversify';
import 'reflect-metadata';
//...more code
const myLib = container.get(TYPES.MyLib);
console.log(myLib); // <--- this prints "_class { randomLib: _class {} }" which is correct, it works here

export default {
  myLib: myLib // <--- this is where I export the object
};

I have another file which includes this file and wants to access the container object.

src/lib/some_library.js:

import { myLib } from 'src/di/di_inversify';
console.log(myLib); // <--- this prints "undefined"

I'm guessing there is something I've missed with InversifyJS, the vanilla JavaScript examples display all the code in one file and not split up so I have no reference. https://github.com/inversify/InversifyJS/blob/master/wiki/basic_js_example.md

basickarl commented 7 years ago

My bad it was me who has misunderstood export.

export default should be just export.