Typescript Container (IOC)
Kinda port of Laravel's illuminate/container to typescript.

Nub Inversion of Control container highly based on illuminate/container from Laravel. You can think of it as a port of illuminate/container to typescript, however, there's no guarantee that everything would work as it should. This module was designed for typescript and thus I cannot guarantee compatibility with ES6 alone.
Installation
npm i --save typescript-container
Known issues / Not working
Contextual Bindings doesn't work just yet.- Storing arbitrary values
- Every other stuffs aside from basic functionality.
- Primitive types as dependency
- tagging
- overriding constructor parameters
- callback supports
Basic Usage
You can start by requiring the ioc container then do your thing.
const Container = require('typescript-container')
const Inject = Container.Inject
const WithDependencies = require('./src/WithDependencies')
const Dependency = require('./src/Dependency')
const app = Container.getInstance()
app.alias(Dependency, 'dependency')
const withDependencies = app.make(WithDependencies)
withDependencies.doStuff()
const Inject = require('typescript-container').Inject
class WithDependencies {
dep;
constructor(@Inject('dependency') dep) {
this.dep = dep
}
doStuff() {
return this.dep.doSomething()
}
}
class Dependency {
doSomething() {
return 'hello'
}
}
injecting dependencies to any other method also works.
Release History
- 0.0.3
- added factory() and singleton()
- 0.0.2
- basic contextual binding added
- 0.0.1
Meta
Jacob Baring – @yakovmeister – so@tfwno.gf
Distributed under the MIT license. See LICENSE
for more information.
https://github.com/yakovmeister/
Contributing
- Fork it (https://github.com/yakovmeister/typescript-container/fork)
- Create your feature branch (
git checkout -b feature/fooBar
) - Commit your changes (
git commit -am 'Add some fooBar'
) - Push to the branch (
git push origin feature/fooBar
) - Create a new Pull Request