tiniocc
v0.0.4
Published
A dead simple ioc container.
Downloads
15
Readme
tiniocc
A dead simple IoC container, with lazyload support.
Installation
yarn add tiniocc
or
npm i tiniocc
Usage
// import the exported function
// you can also require it when using CommonJS
// const { createContainer } = require('tiniocc')
import { createContainer } from 'tiniocc'
// create a container
const container = createContainer()
// register a module named 'module' with plain text content 'content'
container.register('module', 'content')
// access the module via dot notation
// will print 'content'
console.log(container.module)
import { createContainer } from 'tiniocc'
const container = createContainer()
container.register('moduleA', 'content')
// register another module which depends on moduleA
container.register('moduleB', container => container.moduleA + ' content')
console.log(container.moduleA) // will print 'content'
console.log(container.moduleB) // will print 'content content'
note: when using with snowpack, you should import the module as follow:
import tiniocc from 'tiniocc'
const container = tiniocc.createContainer()