Lightweight Dependency Injection Framework for Node.JS Apps - Structure your application business logic
v2.0
Lightweight dependency injection framework to structure application business logic.
The context based approach allows a developer to slice the business logic into small, isolated business actions that communicate to each other via context. That encourages developers to use the same action interface across application code, which makes the code more predictable, easy to define/compose, and test with mock data. And yes - it makes it boring.
module-root/
action.json
action.js
{
"MATH/sum": "./action"
}
module.exports = context => (a, b) => a + b;
const { createContext } = require('@ebay/oja-action');
// context creation can be called for every new flow
const context = await createContext();
// calling action can be done many times within the same context
console.log(await context.action('MATH/sum', 1, 2)); // >> 3
console.log(await context.action('MATH/sum', 5, 2)); // >> 7
In order to realize all benefits of using oja framework you need to do the following:
Install the following modules as part of your application
npm install @ebay/oja-context @ebay/oja-action --save
npm install @ebay/oja-linter --save-dev
Install VSCode extension as part of your VSCode Editor
Note: VSCode extension uses oja-linter to validate your project files (action.json, *.js/mjs) and it will start working as soon as you install @ebay/oja-linter, @ebay/oja-action and @ebay/oja-context under your application dependencies.
Install optional hygen generator
npm install hygen hygen-add -g
hygen-add oja-generators
Example
Feel free to explore examples, a fully functional application.
Each package is documented in a separate readme:
Extension point
Middleware
Feature activation/selection
Flow selection
Pub/sub pattern to decouple producer actions from consumer actions
What if you are "stuck" with express, but like Koa syntax?
This project adheres to the eBay Code of Conduct. By participating in this project you agree to abide by its terms.
Dmytro Semenov
Copyright (c) 2019 eBay Inc.
Released under the MIT License http://www.opensource.org/licenses/MIT