All Projects → zazoomauro → Node Dependency Injection

zazoomauro / Node Dependency Injection

Licence: mit
The NodeDependencyInjection component allows you to standarize and centralize the way objects are constructed in your application.

Programming Languages

javascript
184084 projects - #8 most used programming language
typescript
32286 projects
es6
455 projects
es2015
71 projects
es2017
19 projects
es2016
15 projects

Projects that are alternatives of or similar to Node Dependency Injection

Di
Dependency Injection and IoC framework for PHP
Stars: ✭ 5 (-96.43%)
Mutual labels:  dependency-injection, ioc, ioc-container
alpha-dic
Powerful dependency injection container for node.js
Stars: ✭ 27 (-80.71%)
Mutual labels:  ioc, dependency-injection, ioc-container
DependencyInjector
Lightweight dependency injector
Stars: ✭ 30 (-78.57%)
Mutual labels:  ioc, dependency-injection, ioc-container
React Ioc
Hierarchical Dependency Injection with new React 16 Context API
Stars: ✭ 133 (-5%)
Mutual labels:  dependency-injection, ioc, ioc-container
Typescript Ioc
A Lightweight annotation-based dependency injection container for typescript.
Stars: ✭ 427 (+205%)
Mutual labels:  dependency-injection, ioc, ioc-container
inject
[Archived] See https://github.com/goava/di.
Stars: ✭ 49 (-65%)
Mutual labels:  ioc, dependency-injection, ioc-container
Poodinis
A dependency injection framework for D with support for autowiring.
Stars: ✭ 57 (-59.29%)
Mutual labels:  dependency-injection, ioc, ioc-container
iocgo
A lightweight Inversion of Control (IoC) (Dependency Injection) container for Golang
Stars: ✭ 36 (-74.29%)
Mutual labels:  ioc, dependency-injection, ioc-container
Disco
PSR-11 compatible Dependency Injection Container for PHP.
Stars: ✭ 135 (-3.57%)
Mutual labels:  dependency-injection, ioc, ioc-container
Kangaru
🦘 A dependency injection container for C++11, C++14 and later
Stars: ✭ 297 (+112.14%)
Mutual labels:  dependency-injection, ioc, ioc-container
SwiftInjection
Dependency Injection framework for Swift
Stars: ✭ 21 (-85%)
Mutual labels:  ioc, dependency-injection, ioc-container
Container Ioc
Inversion of Control container & Dependency Injection for Javascript and Node.js apps powered by Typescript.
Stars: ✭ 89 (-36.43%)
Mutual labels:  dependency-manager, dependency-injection, ioc
Reflex
Minimal dependency injection framework for Unity
Stars: ✭ 263 (+87.86%)
Mutual labels:  ioc, dependency-injection, ioc-container
di
🛠 A full-featured dependency injection container for go programming language.
Stars: ✭ 156 (+11.43%)
Mutual labels:  ioc, dependency-injection, ioc-container
vesselize
⛵ A JavaScript IoC container that works seamlessly with Vue.js and React.
Stars: ✭ 22 (-84.29%)
Mutual labels:  ioc, dependency-injection, ioc-container
ThunderboltIoc
One of the very first IoC frameworks for .Net that has no reflection. An IoC that casts its services before thunder casts its bolts.
Stars: ✭ 40 (-71.43%)
Mutual labels:  ioc, dependency-injection, ioc-container
Typhoon
Powerful dependency injection for Objective-C ✨✨ (https://PILGRIM.PH is the pure Swift successor to Typhoon!!)✨✨
Stars: ✭ 2,711 (+1836.43%)
Mutual labels:  dependency-injection, ioc, ioc-container
ashley
Ashley is a dependency injection container for JavaScript.
Stars: ✭ 23 (-83.57%)
Mutual labels:  ioc, dependency-injection, ioc-container
brisk-ioc
fast light brisk ioc/di container on nodejs; Node下快速 轻量的IoC/DI容器,依赖注入,配合装饰器使用
Stars: ✭ 12 (-91.43%)
Mutual labels:  ioc, dependency-injection, ioc-container
Singularity
A extremely fast ioc container for high performance applications
Stars: ✭ 63 (-55%)
Mutual labels:  dependency-injection, ioc, ioc-container

Node Dependency Injection

NDI Logo

A special thanks to Symfony which was a great inspiration and example for this project.

The Node Dependency Injection component allows you to standardize and centralize the way objects are constructed in your application.

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

Installation

npm install --save node-dependency-injection

Usage: register and get services

Imagine you have a Mailer class like this:

// services/Mailer.js

export default class Mailer {
  /**
   * @param {ExampleService} exampleService
   */
  constructor(exampleService) {
    this._exampleService = exampleService;
  }

  ...
}

You can register this in the container as a service:

import {ContainerBuilder} from 'node-dependency-injection'
import Mailer from './services/Mailer'
import ExampleService from './services/ExampleService'

let container = new ContainerBuilder()

container
  .register('service.example', ExampleService)

container
  .register('service.mailer', Mailer)
  .addArgument('service.example')

And get services from your container

const mailer = container.get('service.mailer')

Configuration files: how to load and use configuration files

You can also use configuration files to improve your service configuration

# /path/to/file.yml
services:
  service.example:
    class: 'services/ExampleService'

  service.mailer:
    class: 'services/Mailer'
    arguments: ['@service.example']
import {ContainerBuilder, YamlFileLoader} from 'node-dependency-injection'

let container = new ContainerBuilder()
let loader = new YamlFileLoader(container)
loader.load('/path/to/file.yml')

And get services from your container easily

...
const mailer = container.get('service.mailer')

List of features

  • Configuration files with JS, YAML or JSON.
  • Multiple configuration files
  • Custom relative service directory
  • Compiling container
    • Custom compiler pass
    • Change definition behaviour
  • Using a factory to create services
  • Nullable Dependencies
  • Public or private services
  • Service Aliasing
  • Service Tagging
  • Parameters Injection
  • Lazy Services
  • Deprecate Services
  • Decorate Services
  • Synthetic Services
  • Non Shared Services
  • Parent and Abstract Services
  • Custom Logger
  • Container as Service

Please read full documentation

ExpressJS Usage

If you are using expressJS and you like Node Dependency Injection Framework then I strongly recommend you to use the node-dependency-injection-express-middleware package. That gives you the possibility to retrieve the container from the request.

npm install --save node-dependency-injection-express-middleware
import NDIMiddleware from 'node-dependency-injection-express-middleware'
import express from 'express'

const app = express()

const options = {serviceFilePath: 'some/path/to/config.yml'}
app.use(new NDIMiddleware(options).middleware())

Express Middleware Documentation

TypeScript Usage

If you are using typescript and you like Node Dependency Injection Framework then typing are now provided at node-dependency-injection so you do not have to create custom typing anymore.

npm install --save node-dependency-injection
import { ContainerBuilder } from 'node-dependency-injection'
import MongoClient from './services/MongoClient'
import { Env } from './EnvType'

export async function boot(container = new ContainerBuilder(), env: Env) {
    container.register('Service.MongoClient', MongoClient).addArgument({
        host: env.HOST,
        port: env.PORT,
    })
}

Resources

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].