Git Product home page Git Product logo

adonis-fold's Introduction

AdonisJs Fold ๐Ÿš€

Dependency manager and IoC container for Node.js

NPM Version Build Status Appveyor Coveralls

Fold is a dependency manager for Node.js used by AdonisJs framework. Below is the list of features.

Features

  1. Support for binding dependencies with unique namespaces.
  2. Autoloading multiple directories under a namespace.
  3. Defining aliases for bindings.
  4. Automatic resolution of namespaces and transparent dependency injection.
  5. Support for fakes when writing tests.
  6. Support for service providers, to bind dependencies in structured way.

Installation

You can install the package from npm.

npm i --save adonis-fold

Basic Usage

const { ioc } = require('adonis-fold')

class Foo {
}

ioc.bind('App/Foo', function () {
  return new Foo()
})

const foo = ioc.use('App/Foo')
// return Foo class instance

ioc.with('App/Foo', (Foo) => {
  // Only if App/Foo exists
})

Simple enough! But we do not see the real power of the Ioc container, since we can instantiate the class manually too. Right? NO

Here are the following benefits.

  1. The author of the Foo class can decide how to instantiate the class and return a properly configured instance, instead of leaving it to the consumer.

  2. While you are making use of the Ioc container, one binding can be dependent upon others, without much work. For example

class Foo {
  constructor (config) {
    //
  }
}

ioc.bind('App/Foo', function (app) {
  const config = app.use('App/Config')
  return new Foo(config)
})

const foo = ioc.use('App/Foo')

This time, we injected App/Config behind the scenes and the consumer of the Foo class won't have to worry about passing the config manually.

Moving Forward

Checkout the official documentation at the AdonisJs website for more info.

Tests

Tests are written using japa. Run the following commands to run tests.

npm run test:local

# report coverage
npm run test

# on windows
npm run test:win

Release History

Checkout CHANGELOG.md file for release history.

Meta

AdonisJs โ€“ @adonisframework โ€“ [email protected]

Checkout LICENSE.txt for license information

Harminder Virk (Aman) - https://github.com/thetutlage

adonis-fold's People

Contributors

romainlanz avatar snyk-bot avatar thetutlage avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.