iocfy
TypeScript icon, indicating that this package has built-in type declarations

1.0.4 • Public • Published

Iocfy

A simple IoC module for node.js.

Usage

npm install iocfy

For example, the project structure:

|--service/
   |--user.js
|--model/
   |--user.js
|index.js

First step. Add the beans

model/user.js

class UserModel {
  findOne() {
    return {
      name: 'hello world',
      age: 21,
    };
  }
}

----------------------
service/user.js

class UserService {
  find() {
    this.userModel.findOne();
  }
}

And add a config for Iocfy.

application.json

{
  "beans": {
    "userModel": {
      "class": "model/user"
    },
    "userService": {
      "class": "service/user"
    }
  }
}

Finally, using the Iocfy to manage the beans.

index.js

const Iocfy = require('iocfy');
const config = require('application.json');
Iocfy.load(config);

const UserService = Iocfy.getBean('userService');
console.log(UserService.find());    // { name: 'hello world', age: 21 }

Package Sidebar

Install

npm i iocfy

Weekly Downloads

0

Version

1.0.4

License

ISC

Unpacked Size

10.9 kB

Total Files

7

Last publish

Collaborators

  • linby1991830