<commit_before># AsyncIoC for Node JS

Asyncronous IoC and dependency injection for Node JS.

# Module Signature

```js
module.exports = function(services) { };
```

... where services is an object containing the injected services

# Attributes

## $implement

Defines the service or interface name this module implements.

*Default:* The file or folder name.

```js
module.exports = function(services) { };
module.exports.$implement = 'serviceName';

```

## $inject

Defines the services to be injected for this service. These should be supplied as an array of string values containing the service names.

*Default:* No services ([])

```js
module.exports = myService;
module.exports.$inject = ['dependencyOne', 'dependencyTwo'];

function myService(services) {
	services.dependencyOne.someMethod();
}
```

# Asyncronous Services

## Method 1: Promises

Simply return a promise from the service factory.

```js
module.exports = myService;

function myService(services) {
	var deferred = Q.defer();

	// this service will finish loading in 1 second
	setTimeout(function() {
		deferred.resolve();
	},1000);

	return deferred.promise;
}
```

## Method 2: start() method

Return an object that defines a ```.start()``` method that accepts a Node-style callback (ie: ```function(err)```) to be called on completion. The start method will be called before injecting into the first service.

```js
module.exports = myService;

function myService(services) {

	return {
		start: function(done) {

			// if an error occurs, call done() with the error
			if (someErrorOccurred) done(someErrorOccurred);

			// this service will finish loading in 1 second
			setTimeout(function() {
				done();
			},1000);
		}
	};

}
```<commit_msg>update docs<commit_after># AsyncIoC for Node JS

Asyncronous IoC and dependency injection for Node JS.

## Usage

First create a container:

```js
var ioc = require('async-ioc').createContainer();
```

Then register services on that container:

```js
ioc.register('service', someFunction);
ioc.register('anotherService', require('./anotherservice'));
```

You can specify dependencies for a service:

```js
ioc.register('serviceThree', serviceThreeFactory, ['service', 'anotherService']);
```

And start a service with dependency injection:
```js
ioc.start('serviceThree');
```

You can also chain the methods:

```js
var ioc = require('async-ioc').createContainer()
	.register('service', someFunction)
	.register('anotherService', require('./anotherservice'))
	.register('serviceThree', serviceThreeFactory, ['service', 'anotherService'])
	.start('serviceThree');
```

## Service Signature

The factory/function for the service should have the following signature:

```js
var someService = function(services) {
	// ...
	// service initialization logic
	// ...

	return theService;
};
```

Typically you would expose this in a module:

```js
module.exports = function(services) { };
```

... where services is an object containing the injected services

## Attributes

### $implement

Defines the service or interface name this module implements.

*Default:* The file or folder name.

```js
module.exports = function(services) { };
module.exports.$implement = 'serviceName';

```

### $inject

Defines the services to be injected for this service. These should be supplied as an array of string values containing the service names.

*Default:* No services ([])

```js
module.exports = myService;
module.exports.$inject = ['dependencyOne', 'dependencyTwo'];

function myService(services) {
	services.dependencyOne.someMethod();
}
```

## Asyncronous Services

### Method 1: Promises

Simply return a promise from the service factory.

```js
module.exports = myService;

function myService(services) {
	var deferred = Q.defer();

	// this service will finish loading in 1 second
	setTimeout(function() {
		deferred.resolve();
	},1000);

	return deferred.promise;
}
```

### Method 2: start() method

Return an object that defines a ```.start()``` method that accepts a Node-style callback (ie: ```function(err)```) to be called on completion. The start method will be called before injecting into the first service.

```js
module.exports = myService;

function myService(services) {

	return {
		start: function(done) {

			// if an error occurs, call done() with the error
			if (someErrorOccurred) done(someErrorOccurred);

			// this service will finish loading in 1 second
			setTimeout(function() {
				done();
			},1000);
		}
	};

}
```

### Shutdown / Stop process

TODO:
{'fraction_non_alphanumeric': 0.12955555555555556, 'fraction_numerical': 0.005333333333333333, 'mean_word_length': 4.55679012345679, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6358241', 'n_tokens_mistral': 1373, 'n_tokens_neox': 1259, 'n_words': 464}