Coder Social home page Coder Social logo

phreatic's Introduction

Phreatic Dependency Injector

In many frameworks across languages, exists the implementation of this well known design pattern, like Spring MVC, Angular, .NET, etc.

Well, the idea of this was not to create just another IoC based dependency injector. The main motivation was the lack of a DI that resolves circular dependencies without messing too much with runtime, reflection, or overcomplicating the solution.

Installation

Greenkeeper badge

npm install --save phreatic
# OR
yarn add phreatic

Objectives

  • Be Awesome.
  • Be super simple.
  • Well tested. Dependency Injection is the base of well a architectured system.

Inspiration

  • Spring framework
  • Angular
  • InversifyJS
  • typescript-ioc

Features

  • Solves circular dependencies.
  • Zero dependencies.
  • Isomorphic/Universal.
  • Inspired by KISS and SOLID principles.
  • Lazy dependency resolution.

Caveats

  • We do not deal with the circular dependencies made by you and your imports. Please avoid doing the following kind of imports A => B => C => A. Just use @Inject("className").

Example

import { Inject, Injectable, get, createInjectable } from "phreatic";

@Injectable
export class User {
  public name = "user pepito";
  public password;
  @Inject("HttpService") public http;
}

export class Role {
  public name = "role pepito";
  public password;
}

@Injectable
export class HttpService {
  public name = "http service";
  @Inject("User") public user: User;
  @Inject("Role") public role: Role;
}

createInjectable(new Role());

const http = get(HttpService);
const user = get<any>("User");
// the same as
// const http = new HttpService();
// const user = new User();

// Valid uses
console.log(http.role.name);
console.log(http.user.name);
console.log(user.http.user.http.user.http.user.name);
console.log(user.http.user.http.user.http.name);

Development

Just the usual.

# Install deps
yarn
# Change the code
# Build it
yarn build
# Test it
yarn test
# submit your Pull Request or Open an issue

phreatic's People

Contributors

bertilxi avatar greenkeeper[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  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.