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.
- folder structure:
module-root/
action.json
action.js
- action.json:
{
"MATH/sum": "./action"
}
- action.js
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
- Open VS Code
- Press F1
- Type "install"
- Select "Extensions: Install Extension".
- Select vscode-oja from the list
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:
- oja-action - Provides action discovery for oja actions based on dependency injection.
- oja-context - Provides dependency injection.
- oja-generators - Provides code and unit test generation for oja-action framework.
- oja-flow - Provides a flow components based on pub/sub pattern with event backlog. This is former oja 1.0 implementation.
- oja-tools - Builds on oja-action to provide tools composing actions into higher level actions and/or instrument them via pipe pattern.
- examples - Example project demonstrating the use of dependency injection based on oja-action
- vscode-oja - VS Code extension that simplifies oja-action dependency injection usage with automatic suggestions and action discovery.
- oja-linter - Oja linter for oja-action dependency injection layer that validates your project and discovers any unreachable actions (deleted/modified) at the point of the use of the action.
- oja-pubsub - Provides a way to organize actions into publishers and subscribers roles when the same business events need to be consumed by multiple consumer actions.
- TBD: oja-workers - Provides an action pool that can be used to separate actions or group of actions into their own isolated execution environments based on Node v12 lightweight workers.
- TBD: oja-cloud - Provides an adaptor layer to organize and deploy actions to distributed environments aka lambda/serverless.
-
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