All Projects â†’ Livshitz â†’ di.libx.js

Livshitz / di.libx.js

Licence: MIT License
💉 di.libx.js - Lightweight & non intrusive Dependency Injection module that supports async/deferred resolution and uglified support

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to di.libx.js

diod
A very opinionated inversion of control (IoC) container and dependency injector for Typescript, Node.js or browser apps.
Stars: ✭ 36 (+12.5%)
Mutual labels:  dependency-injection, inversion-of-control
mindjs
Minimalistic, pure Node.js framework superpowered with Dependency Injection 💡 💻 🚀
Stars: ✭ 17 (-46.87%)
Mutual labels:  dependency-injection, inversion-of-control
jimple
Just a dependency injection container to NodeJS and to the browser using new ES6 features
Stars: ✭ 72 (+125%)
Mutual labels:  dependency-injection, inversion-of-control
Components.js
🧩 A semantic dependency injection framework
Stars: ✭ 34 (+6.25%)
Mutual labels:  dependency-injection, inversion-of-control
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 (+25%)
Mutual labels:  dependency-injection, inversion-of-control
dargo
Dependency Injection for GO
Stars: ✭ 26 (-18.75%)
Mutual labels:  dependency-injection, inversion-of-control
ufw
A minimalist framework for rapid server side applications prototyping in C++ with dependency injection support.
Stars: ✭ 19 (-40.62%)
Mutual labels:  dependency-injection, inversion-of-control
waiter
Dependency injection, Inversion of control container for rust with compile time binding.
Stars: ✭ 71 (+121.88%)
Mutual labels:  dependency-injection, inversion-of-control
vue-ioc
IoC and DI for Vue powered by InversifyJS and inspired by Angular Module syntactic sugar.
Stars: ✭ 39 (+21.88%)
Mutual labels:  dependency-injection, inversion-of-control
inversify-koa-utils
inversify-koa-utils is a module based on inversify-express-utils. This module has utilities for koa 2 applications development using decorators and IoC Dependency Injection (with inversify)
Stars: ✭ 27 (-15.62%)
Mutual labels:  dependency-injection, inversion-of-control
vesselize
⛵ A JavaScript IoC container that works seamlessly with Vue.js and React.
Stars: ✭ 22 (-31.25%)
Mutual labels:  dependency-injection, inversion-of-control
nodejs-boilerplate
Clean Architecture for node.js projects (Typescript + Express + TypeORM + Typedi)
Stars: ✭ 199 (+521.88%)
Mutual labels:  dependency-injection, inversion-of-control
awilix-express
Awilix helpers/middleware for Express
Stars: ✭ 100 (+212.5%)
Mutual labels:  dependency-injection, inversion-of-control
saber
Dependency injection (DI) & Inversion of Control (IoC) command line tool for Swift based on code generation
Stars: ✭ 21 (-34.37%)
Mutual labels:  dependency-injection, inversion-of-control
iocgo
A lightweight Inversion of Control (IoC) (Dependency Injection) container for Golang
Stars: ✭ 36 (+12.5%)
Mutual labels:  dependency-injection, inversion-of-control
avaje-inject
Dependency injection via APT (source code generation) ala "Server side Dagger DI"
Stars: ✭ 114 (+256.25%)
Mutual labels:  dependency-injection, inversion-of-control
Typhoon
Powerful dependency injection for Objective-C ✨✨ (https://PILGRIM.PH is the pure Swift successor to Typhoon!!)✨✨
Stars: ✭ 2,711 (+8371.88%)
Mutual labels:  dependency-injection, inversion-of-control
stashbox
A lightweight, fast, and portable dependency injection framework for .NET-based solutions.
Stars: ✭ 120 (+275%)
Mutual labels:  dependency-injection, inversion-of-control
di
Simple and yet powerful Dependency Injection for Go
Stars: ✭ 188 (+487.5%)
Mutual labels:  dependency-injection, inversion-of-control
Griffin.Container
Inversion of control container with (almost) zero configuration
Stars: ✭ 13 (-59.37%)
Mutual labels:  dependency-injection, inversion-of-control

Node.js CI

💉 di.libx.js

Lightweight & non intrusive Dependency Injection module that supports async/deferred resolution and uglified support for Typescript and JavaScript in 3.3kB gzipped (14.7kB on disk). Feature complete, fast, reliable and well tested.

Features:

  • Deferred resolution - asynchronously require dependencies that are not yet available and resolve once it is.
  • Automatic resolve of function params - resolve & map dependencies manually or as function's parameters
  • NodeJS & browser - browserified version ready to use from CDN.
  • Explicit or implicit dependencies - works with uglified files by specified dependencies' names or implicitly from function/class name.
  • Typescript support - specify injected instance's types.
  • Non Intrusive - register any modules; your internal modules or 3rd-party modules without modifing its code. No attribute wrapping needed.

Use:

Install via yarn (recommended):

yarn add di.libx.js

Install via npm:

npm install --save di.libx.js

Browser:

https://cdn.jsdelivr.net/npm/di.libx.js@latest/dist/browser.min.js
(Modules are loaded into `window.libx.di` object).

Use this library in browser from CDN, code example, live example.
Or include from node_modules.


Basic usage:

import DependencyInjector from 'di.libx.js';
// const DependencyInjector = require('di.libx.js');

const di = new DependencyInjector();

const myFunc = () => {
    console.log('This is myFunc');
};

// Register a dependencies
di.register('func', myFunc);

// Require dependencies. Will wait until all dependencies are ready
// Note that awaiting this function will create dead lock unless the other register will called in parallel
di.inject((func, anonFunc) => {
    func();
    anonFunc();
});

// Register another dependencies. Will trigger execution of the `require`
di.register('anonFunc', () => console.log('Anonymous func'));

More examples:

// in your web app add:
// <script src="https://cdn.jsdelivr.net/npm/di.libx.js@latest/dist/browser.min.js"></script>

var myModule = { somveVar: 1 };
libx.di.register('myModule', myModule);

// async require:
await libx.di.inject((myModule) => {
    console.log('dependency resolved!', myModule);
    // execute your code here. 'await' is optional incase you want it to be async and continue execution.
    // note: the callback will be triggered only once the dependency is registered somewhere else in your program. Beware not to create dead-lock.
});

// synchronously get a module:
mod = await libx.di.require('myModule');

// register new module with other dependencies:
mod = libx.di.injectAndRegister('myNewModule', (myModule) => {
    return () => console.log('this came from myNewModule!', myModule);
});

// inject for uglified code (second param is module identifiers, injected by position. So `myUglifiedModule` == `myModule`):
libx.di.inject(
    (myUglifiedModule) => {
        console.log('unglified dependency resolved!', myUglifiedModule);
    },
    ['myModule']
);
Sub Container:
// Register a local scoped container that inherits from the main container. 
// All locally registered modules will be disposed once exited scope.
const subContainer = new DependencyInjector(di);
subContainer.register('moduleB', di.initiate(ModuleB));

// Main execution point:
subContainer.inject((moduleB) => {
	const result = moduleB.Run(10);
	console.log('Result: ', result);
}).then(() => {
	console.log('DONE!');
});

Check more examples in unit-test at tests.


Develop:

Build:

$ yarn build

Watch & Build:

$ yarn watch

Run tests:

$ yarn test

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