Skip to content

Latest commit

 

History

History
93 lines (58 loc) · 1.83 KB

README.md

File metadata and controls

93 lines (58 loc) · 1.83 KB

iocjs

A basic ioc container for JavaScript applications

installation

npm install @hkfrei/iocjs

getting started

Define the ioc container in your main JavaScript entry file.

// main.js
import IocContainer from "@hkfrei/iocjs"

const appIoc = new IocContainer()

register dependecies

register a transient class

appIoc.register({ name:"urlGateway", definition:UrlGateway });

register a transient class with initial values in the constructor

appIoc.register({ name: "initValue", definition:{ score:1 } })
appIoc.register({ name:"urlGateway", definition:UrlGateway, dependencies:["initValue"] });

register a transient class with dependecy classes

appIoc.register({ name:"urlGateway", definition:UrlGateway, dependencies:["initValue"] });
appIoc.register({ name:"mapPm", definition:MapPm, dependencies:["urlGateway] })

register a singleton

appIoc.register({ name:"urlGateway", definition:UrlGateway, singleton:true });

retrieve Instances

You can get instances of the registered classes the following way.

const mapPm = appIoc.get("mapPm")

Available Scripts

npm run test

Launches the test runner in the interactive watch mode.

npm run build

Builds the app for production to the dist folder.

Built with

For a full list of used libraries, have a look at package.json

Contribution

Contributions are welcome! Please reach out to hkfrei@karten-werk.ch if you want to have more information.

License

This project is Licensed under the GNU GENERAL PUBLIC License. See LICENSE.

Contact

Karten-werk GmbH Hanskaspar Frei hkfrei@karten-werk.ch