Skip to content

khlbrg/js-ioc-container

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

IoC Container for JavaScript

This script is an example of a basic IoC container in JavaScript.

Read the full article on Medium: Creating an IoC Container with dependency injection in JavaScript - https://medium.com/the-everyday-developer/creating-an-ioc-container-with-dependency-injection-in-javascript-9db228d34060

Register classes

const container = new Container()

container.register('config', {key:value})
container.register('downloader', Downloader, ['config']) 
container.singleton('logger', Logger, ['config'])

Retrieve classes from container

container.get('config')
container.get('downloader') // New download instance with config injected in constructor 
container.get('logger') // Logger instance
container.get('logger') // Same logger instance

Run test

npm install
npm test

About

A basic IoC Container written in JavaScript

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published