node-dependency-injection-express-middleware

1.2.2 • Public • Published

Node Dependency Injection Express Middleware

NDI Logo

A Node Dependency Injection middleware for Express

Npm Version Build Status Dependencies DevDependencies Code Coverage Maintainability Coding Standard Known Vulnerabilities Npm Downloads License

Installation

npm install --save node-dependency-injection-express-middleware

Usage

Minimal configuration

import NodeInjectionMiddleware from 'node-dependency-injection-express-middleware'
import express from 'express'
 
const app = express()
 
const options = {serviceFilePath: 'some/path/to/config.yml'}
app.use(new NodeInjectionMiddleware(options).middleware())

Options

Name Required Type Value Default Value
serviceFilePath true string
compile false boolean false
compilerPass false array []
logger false class or object null
containerReferenceAsService false boolean false
defaultDir false string null

How to use all options

import MyCustomPass from 'CompilerPass/MyCustomPass'
import AnotherAwesomePass from 'CompilerPass/AnotherAwesomePass'
import MyCustomLogger from 'MyCustomLogger'
import NDIMiddleware from 'node-dependency-injection-express-middleware'
import express from 'express'
 
const app = express()
 
const options = {
  serviceFilePath: 'some/path/to/config.yml', 
  compile: true,
  compilerPass: [new MyCustomPass(), new AnotherAwesomePass()],
  logger: new MyCustomLogger(),
  containerReferenceAsService: true,
  defaultDir: '/some/cool/dir',
}
app.use(new NDIMiddleware(options).middleware())

How to get the container

app.get('/some/action', (req, res, next) => {
  const container = req.container
  const myAwesomeService = container.get('some.awesome.service')
  ...
})

Please, read the FULL DOCUMENTATION

Resources

Package Sidebar

Install

npm i node-dependency-injection-express-middleware

Weekly Downloads

45

Version

1.2.2

License

MIT

Unpacked Size

18.9 kB

Total Files

9

Last publish

Collaborators

  • zazoomauro