Typescript Container (IOC)
Laravel (illuminate/container) inspired/based IoC container.


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
- Contextual Bindings doesn't work just yet.
- Every other stuffs aside from basic functionality.
Basic Usage
You can start by requiring the ioc container then do your thing.
const Container = require('typescript-container')
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 } = app
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.0-alpha.2
- basic contextual binding added
- 0.0.0-alpha.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