0.6.5 • Published 7 years ago

ioccontainer v0.6.5

Weekly downloads
15
License
GPL
Repository
github
Last release
7 years ago

IocContainer

This is a dependency injection module

Install

npm install ioccontainer

Example

Main file: hello-world.js

"use strict";

var ioc = require("ioccontainer");
ioc.initialize("ioc-config.json");

var hello = ioc.resolve("hello");
console.log(hello.getMessage());

Application context file: ioc-config.js

{
	"bean" : [
		{ 
			"id": "hello", 
			"class": "/path/hello.js",
			"init": "initialize",
			"set" : [
				{ "method": "setMessage", "value": "Hello world !!!!" }
				] 
			}
	]

}

Bean file: hello.js

"use strict";

var message;

var Hello = function() {
	message = "";
};

Hello.prototype.initialize = function() {
};

Hello.prototype.setMessage = function(value) {
	message = value;
};

Hello.prototype.getMessage = function() {
	return message;
};

module.exports = new Hello();

Run

node hello-world.js

API

initialize(path-of-configuration-file)

set path of configuration file

resolve(id-class)

retrieve class specified with id set in configuration file

Example configuration file

{
	"bean" : [
		{ "id": "require", "class": "npm_module" },
		{ "id": "other", "class": "other.js" },
		{ "id": "json", "class": "file.json" },
		{ 
			"id": "mymodule", 
			"class": "module.js",
			"init": "initialize",
			"set" : [
				{ "method": "setValue", "value": "My value" },
				{ "method": "setJSON", "ref": "json" },
				{ "method": "setRequire", "ref": "require" },
				{ "method": "setBean", "ref": "other" }
				] 
			}
	]
}

For any javascript module declare a bean with:

id required

unique id name

class required

path of class

initialize optional

initialize method

set optional

"method": name of method for dependency injection, using "value" for string or number or "ref" for other module declared in configuration file

Contributors

0.6.5

7 years ago

0.6.4

7 years ago

0.6.3

8 years ago

0.6.2

9 years ago

0.6.1

9 years ago

0.5.31

9 years ago

0.5.30

9 years ago

0.5.20

9 years ago

0.5.9

9 years ago

0.5.8

9 years ago

0.5.7

9 years ago

0.5.6

10 years ago

0.5.5

10 years ago

0.5.4

10 years ago

0.5.3

10 years ago

0.5.2

10 years ago

0.5.1

10 years ago

0.5.0

10 years ago

0.4.15

10 years ago

0.4.14

10 years ago

0.4.13

10 years ago

0.4.12

10 years ago

0.4.11

10 years ago

0.4.10

10 years ago

0.4.9

10 years ago

0.4.8

10 years ago

0.4.7

10 years ago

0.4.6

10 years ago

0.4.5

10 years ago

0.4.4

10 years ago

0.4.2

10 years ago

0.4.1

10 years ago

0.4.0

10 years ago

0.3.8

10 years ago