thiagobustamante / typescript-ioc

A Lightweight annotation-based dependency injection container for typescript.
MIT License
526 stars 64 forks source link

Shared container across packages #43

Closed castorw closed 6 years ago

castorw commented 6 years ago

Hello there,

I am struggling with sharing a container between multiple node packages. I need a package, which is a dependency to the launched package, to register its own singleton services. Then the launched package may register its own services while still being able to use the services registered by the dependency package. Imaging a situation in which we have a core package and an application package using the core functionality.

From looks of the code, this could be achieved by adding ability to somehow "merge" bindings within IoCContainer class, which is internal and cannot be manipulated with.

Any chances of resolving this?

Thank you.

castorw commented 6 years ago

Okay, used brain for a bit and found a solution:

Created a folder named ioc in the core package, put an index.js file inside containing:

module.exports = require("typescript-ioc/es6");

Then in my application package I use:

import { Inject } from "core-package/ioc";

instead of

import { Inject } from "typescript-ioc/es6";

So closing this.