# tramway-command-di-factory

> A command factory for use when leveraging tramway-core-dependency-injector

Latest version **1.0.1** (published 2019-06-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install tramway-command-di-factory
pnpm add tramway-command-di-factory
yarn add tramway-command-di-factory
bun add tramway-command-di-factory
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2019-06-23 |
| First published | 2018-08-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 7.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Julian Wolfe |
| Maintainers | julianwolfe |

## Links

- npm: https://www.npmjs.com/package/tramway-command-di-factory
- Repository: https://gitlab.com/tramwayjs/tramway-command-di-factory
- Homepage: https://gitlab.com/tramwayjs/tramway-command-di-factory#README
- Issues: https://gitlab.com/tramwayjs/tramway-command-di-factory/issues?label_name%5B%5D=bug
- npm.io page: https://npm.io/package/tramway-command-di-factory

## Recent versions

- 1.0.1 (latest) — 2019-06-23
- 1.0.0 — 2018-08-04

## README

Tramway Command Dependency Injector Factory is a plugin for `tramway-command` that lets you configure your commands configured with `tramway-core-dependency-injector`. It includes:

1. The DICommandFactory class

# Installation:
1. `npm install tramway-command-di-factory`

# Example project:
https://gitlab.com/tramwayjs/tramway-command-example

# Documentation

## Recommended Folder Structure
- config/parameters/global
- config/services
- commands

## Implementing with Dependency Injection
With the tramway-command-di-factory, you are able to use the Dependency Injection library to build and manage your commands and Command Resolver setup.

### Setup

PROJECT_ROOT / src / config / services / core.js

```javascript
import CommandResolver from 'tramway-command';
import DICommandFactory from 'tramway-command-di-factory';

export default {
    "app": {
        "class": CommandResolver,
        "constructor": [
            {"type": "parameter", "key": "commands"},
            {"type": "service", "key": "factory.command"},
        ],
    },
    "factory.command": {
        "class": DICommandFactory,
        "constructor": [
            {"type": "parameter", "key": "commands"},
        ]
    }
}
```

### Register your commands as services

PROJECT_ROOT / src / config / services / commands.js

```javascript
import {TestCommand} from '../../commands';

export default {
    "command.test": {
        "class": TestCommand,
        "constructor": [],
    }
}
```

### Add a mapper of command cli to command service to the parameters

PROJECT_ROOT / src / config / parameters / global / commands.js

```javascript
export default {
    "test:command": "command.test",
}
```

### Have the runner file get the CommandResolver from the dependency injection container and run it

PROJECT_ROOT / src / COMMAND_RUNNER_FILE.js

```javascript
import {DependencyResolver, dependencies} from 'tramway-core-dependency-injector';
import * as parameters from './config/parameters';
import services from './config/services';

const {ParametersManager, ServicesManager} = dependencies;
DependencyResolver.create(new ServicesManager(), new ParametersManager()).initialize(services, parameters);

DependencyResolver.getService('app').run();
```

---
_Source: https://npm.io/package/tramway-command-di-factory · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
