<commit_before># Needlepoint

![Build Status](https://travis-ci.org/andrewmunsell/needlepoint.svg) [![Code Climate](https://codeclimate.com/github/andrewmunsell/needlepoint/badges/gpa.svg)](https://codeclimate.com/github/andrewmunsell/needlepoint) [![Test Coverage](https://codeclimate.com/github/andrewmunsell/needlepoint/badges/coverage.svg)](https://codeclimate.com/github/andrewmunsell/needlepoint/coverage)

Needlepoint is a dependency injection framework for Node.js and other Javascript
environments where ES6 is supported.

Needlepoint is licensed under the MIT license.

**Note: This library is very early in development and was largely developed as
an exercise, though I intend to use Needlepoint in my own future projects.**

## Requirements

Needlepoint requires a Javascript environment such as Node.js. Though
the library is designed to use new features such as ES6 classes and the proposed
ES7 decorators, Babel is included as a dependency to make the library compatible
with environments that do not support these features directly.

## Getting Started

To use Needlepoint, install it with `npm`:

```
npm install --save needlepoint
```

If you're not using a Javascript environment that supports both ES6 classes and
ES7-style decorators (e.g. Node.JS), then you must configure Babel. This can be
done pretty easily:

```
require('babel/register')({
    optional: ['es7.decorators'],

    // A lot of NPM modules are precompiled so Babel ignores node_modules/*
    // by default, but Needlepoint is NOT pre-compiled so we change the ignore
    // rules to ignore everything *except* Needlepoint.
    ignore: /node_modules\/(?!needlepoint)/
});
```

After this, you can simply import the container where ever your application
needs to inject dependencies:

```
import {container} from 'needlepoint';
```

From there, you can resolve dependencies:

```
import {container} from 'needlepoint';
import {MyDependency} from './my-dependency';

var instanceOfDependency = container.resolve(MyDependency);
instanceOfDependency.performMethod();
```

You can also declare dependencies of your classes with the `@dependencies()`
decorator:

```
import {container, dependencies} from 'needlepoint';
import {MyDependency} from './my-dependency';

@dependencies(MyDependency)
class HasDependencies {
    constructor(myDependency) {
        this.myDependency = myDependency;
    }
}

var instance = container.resolve(HasDependencies);
instance.myDependency.performMethod();
```

Dependencies of a class are injected through the constructor. The objects passed
into the constructor are instances of the requested dependencies.

Or, if you want a class to be a singleton (i.e. only one instance of the class
will be created for your entire application):

```
import {container, singleton} from 'needlepoint';

@singleton
class SingletonDependency {
    constructor() {

    }
}
```

If a class is declared to be a `@singleton`, then one instance will be created
the first time the class is listed as a dependency or resolved, and this
instance will be cached and used when other classes need an instance of it.
<commit_msg>Remove section about ignoring the needlepoint directory<commit_after># Needlepoint

![Build Status](https://travis-ci.org/andrewmunsell/needlepoint.svg) [![Code Climate](https://codeclimate.com/github/andrewmunsell/needlepoint/badges/gpa.svg)](https://codeclimate.com/github/andrewmunsell/needlepoint) [![Test Coverage](https://codeclimate.com/github/andrewmunsell/needlepoint/badges/coverage.svg)](https://codeclimate.com/github/andrewmunsell/needlepoint/coverage)

Needlepoint is a dependency injection framework for Node.js and other Javascript
environments where ES6 is supported.

Needlepoint is licensed under the MIT license.

**Note: This library is very early in development and was largely developed as
an exercise, though I intend to use Needlepoint in my own future projects.**

## Requirements

Needlepoint requires a Javascript environment such as Node.js. Though
the library is designed to use new features such as ES6 classes and the proposed
ES7 decorators, Babel is included as a dependency to make the library compatible
with environments that do not support these features directly.

## Getting Started

To use Needlepoint, install it with `npm`:

```
npm install --save needlepoint
```

If you're not using a Javascript environment that supports both ES6 classes and
ES7-style decorators (e.g. Node.JS), then you must configure Babel. This can be
done pretty easily:

```
require('babel/register')({
    optional: ['es7.decorators']
});
```

After this, you can simply import the container where ever your application
needs to inject dependencies:

```
import {container} from 'needlepoint';
```

From there, you can resolve dependencies:

```
import {container} from 'needlepoint';
import {MyDependency} from './my-dependency';

var instanceOfDependency = container.resolve(MyDependency);
instanceOfDependency.performMethod();
```

You can also declare dependencies of your classes with the `@dependencies()`
decorator:

```
import {container, dependencies} from 'needlepoint';
import {MyDependency} from './my-dependency';

@dependencies(MyDependency)
class HasDependencies {
    constructor(myDependency) {
        this.myDependency = myDependency;
    }
}

var instance = container.resolve(HasDependencies);
instance.myDependency.performMethod();
```

Dependencies of a class are injected through the constructor. The objects passed
into the constructor are instances of the requested dependencies.

Or, if you want a class to be a singleton (i.e. only one instance of the class
will be created for your entire application):

```
import {container, singleton} from 'needlepoint';

@singleton
class SingletonDependency {
    constructor() {

    }
}
```

If a class is declared to be a `@singleton`, then one instance will be created
the first time the class is listed as a dependency or resolved, and this
instance will be cached and used when other classes need an instance of it.

{'fraction_non_alphanumeric': 0.08873776745728977, 'fraction_numerical': 0.0019903798308177146, 'mean_word_length': 5.023976023976024, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 10, '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': '6010646', 'n_tokens_mistral': 1663, 'n_tokens_neox': 1572, 'n_words': 665}