<commit_before><img src="https://opentable.github.io/spur/logos/Spur-IoC.png?rand=1" width="100%" alt="Spur: IoC" />

Dependency Injection library for [Node.js](http://nodejs.org/).

[![npm version](https://badge.fury.io/js/spur-ioc.svg)](http://badge.fury.io/js/spur-ioc)
[![Build Status](https://travis-ci.org/opentable/spur-ioc.svg?branch=master)](https://travis-ci.org/opentable/spur-ioc)
[![Dependencies](https://david-dm.org/opentable/spur-ioc.svg)](https://david-dm.org/opentable/spur-ioc)
[![devDependency Status](https://david-dm.org/opentable/spur-ioc/dev-status.svg)](https://david-dm.org/opentable/spur-ioc?type=dev)

# About the Spur Framework

The Spur Framework is a collection of commonly used Node.JS libraries used to create common application types with shared libraries.

[Visit NPMJS.org for a full list of Spur Framework libraries](https://www.npmjs.com/browse/keyword/spur-framework) >>

# Topics

- [Features](#features)
- [What is inversion of control and why you should use it?](#what-is-inversion-of-control-and-why-you-should-use-it)
- [Quick start](#quick-start)
    - [Usage](#usage)
    - [Writing tests](#writing-tests)
- [API Reference](API.md)
- [Contributing](#contributing)
- [License](#license)

# Features

  * Dependency injection (IoC) inspired by AngularJS
  * Auto injects folders
  * Ability to merge injectors
  * Ability to link injectors
  * Makes testing super easy
    * Ability to substitute dependencies in tests
  * Resolution of dependencies by querying via regular expresion
  * Clear error stack trace reporting

# What is inversion of control and why you should use it?

[Inversion of Control (IoC)](http://en.wikipedia.org/wiki/Inversion_of_control) is also known as Dependency Injection (DI). IoC is a pattern in which objects define their external dependencies through constructor arguments or the use of a container factory. In short, the dependency is pushed to the class from the outside. All that means is that you shouldn't instantiate dependencies from inside the class.

Inversion of control is used to increase modularity of the program and make it extensible, and has applications in object-oriented programming and other programming paradigms.

It allows for the creation of cleaner and more modular code that is easier to develop, test and maintain:

* Single responsibility classes
* Easier mocking of objects for test fixtures
* Easier debugging in Node.js' async environment

# Quick start

## Installation

```bash
$ npm install spur-ioc --save
```

## Usage

Here is a quick example that sets up the definition of an injector, some dependencies and a startup script.

#### `src/injector.js`

```javascript
var spur = require("spur-ioc");

module.exports = function(){
  // define a  new injector
  var ioc = spur.create("demo");


  //register external dependencies or globals
  ioc.registerDependencies({
    "_"           : require("underscore"),
    "path"        : require("path"),
    "console"     : console,
    "nodeProcess" : process
  });

  // register folders in your project to be autoinjected
  ioc.registerFolders(__dirname, [
    "demo"
  ]);

  return ioc;
}
```

#### `src/demo/Tasks.js`

Example of file that depends on an injectable dependency. This example shows the usage of underscore (_).

```javascript
module.exports = function(_){
    return _.map([1,2,3], function(num) {
        return "Task " + num
    });
}
```

#### `src/demo/TasksPrinter.js`

This example injects Tasks and console dependencies, both previously defined in the injector.

```javascript
module.exports = function(Tasks, console){
    return {
        print:function(){
            console.log(Tasks)
        }
    };
}
```

#### `src/start.js` (top declaration file)

Example of how to create an instance of the injector and start the app by using one of its dependencies.<commit_msg>Adding note about node versions and cleaning up some readme issues.<commit_after><img src="https://opentable.github.io/spur/logos/Spur-IoC.png?rand=1" width="100%" alt="Spur: IoC" />

Dependency Injection library for [Node.js](http://nodejs.org/).

[![npm version](https://badge.fury.io/js/spur-ioc.svg)](http://badge.fury.io/js/spur-ioc)
[![Build Status](https://travis-ci.org/opentable/spur-ioc.svg?branch=master)](https://travis-ci.org/opentable/spur-ioc)
[![Dependencies](https://david-dm.org/opentable/spur-ioc.svg)](https://david-dm.org/opentable/spur-ioc)
[![devDependency Status](https://david-dm.org/opentable/spur-ioc/dev-status.svg)](https://david-dm.org/opentable/spur-ioc?type=dev)

# About the Spur Framework

The Spur Framework is a collection of commonly used Node.JS libraries used to create common application types with shared libraries.

[Visit NPMJS.org for a full list of Spur Framework libraries](https://www.npmjs.com/browse/keyword/spur-framework) >>

# Topics

- [Features](#features)
- [What is inversion of control and why you should use it?](#what-is-inversion-of-control-and-why-you-should-use-it)
- [Quick start](#quick-start)
    - [Usage](#usage)
    - [Writing tests](#writing-tests)
- [API Reference](API.md)
- [Contributing](#contributing)
- [License](#license)

# Features

  * Dependency injection (IoC) inspired by AngularJS
  * Auto injects folders
  * Ability to merge injectors
  * Ability to link injectors
  * Makes testing super easy
    * Ability to substitute dependencies in tests
  * Resolution of dependencies by querying via regular expression
  * Clear error stack trace reporting
  * Supports active Node versions in the [LTS Schedule](https://github.com/nodejs/LTS#lts-schedule). ([view current versions](.travis.yml))

# What is inversion of control and why you should use it?

[Inversion of Control (IoC)](http://en.wikipedia.org/wiki/Inversion_of_control) is also known as Dependency Injection (DI). IoC is a pattern in which objects define their external dependencies through constructor arguments or the use of a container factory. In short, the dependency is pushed to the class from the outside. All that means is that you shouldn't instantiate dependencies from inside the class.

Inversion of control is used to increase modularity of the program and make it extensible, and has applications in object-oriented programming and other programming paradigms.

It allows for the creation of cleaner and more modular code that is easier to develop, test and maintain:

* Single responsibility classes
* Easier mocking of objects for test fixtures
* Easier debugging in Node.js' async environment

# Quick start

## Installation

```bash
$ npm install spur-ioc --save
```

## Usage

Here is a quick example that sets up the definition of an injector, some dependencies and a startup script.

#### `src/injector.js`

```javascript
var spur = require("spur-ioc");

module.exports = function(){
  // define a  new injector
  var ioc = spur.create("demo");


  //register external dependencies or globals
  ioc.registerDependencies({
    "_"           : require("underscore"),
    "path"        : require("path"),
    "console"     : console,
    "nodeProcess" : process
  });

  // register folders in your project to be auto-injected
  ioc.registerFolders(__dirname, [
    "demo"
  ]);

  return ioc;
}
```

#### `src/demo/Tasks.js`

Example of file that depends on an injectable dependency. This example shows the usage of underscore (_).

```javascript
module.exports = function(_){
    return _.map([1,2,3], function(num) {
        return "Task " + num;
    });
}
```

#### `src/demo/TasksPrinter.js`

This example injects Tasks and console dependencies, both previously defined in the injector.

```javascript
module.exports = function(Tasks, console){
    return {
        print: function(){
          console.log(Tasks);
        }
    };
}
```

#### `src/start.js` (top declaration file)

Example of how to create an instance of the injector and start the app by using one of its dependencies.
{'fraction_non_alphanumeric': 0.11907470610542283, 'fraction_numerical': 0.0017696877765137151, 'mean_word_length': 4.023492063492063, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 19, 'lorem ipsum': 0, 'www.': 2, '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': '7332514', 'n_tokens_mistral': 2432, 'n_tokens_neox': 2326, 'n_words': 781}