Mini IOC container

JavaScriptDependency injectionSOLID
Mini IOC container - Banner

Dependency injection means avoiding a direct dependency between two classes by injecting the dependency instead of defining it statically.

A dependency container stores all of an application's dependencies. It's what builds them and injects them into a class.

Mini IOC container is a simple container, ready to use. Install it:

npm i @herytz/ioc-container

configure it

import IOCContainer from '@herytz/ioc-container'
import { SimpleService } from './service/simpleService'
 
const TYPES = {
	SimpleService: 'SimpleService'
}
 
const container = new IOCContainer()
 
container.set(TYPES.SimpleService, new SimpleService())
 
export default container

use it

// Import statement
 
const simpleService = container.get(TYPES.SimpleService)