Home | Documentation | Core | CLI | Install |
- Config
- Controller
- Dependency Manager
- Model
- Service
- View
Dependency Manager
The Dependency Manager is kind of a Swiss-Army knife of useful interrelated tools. It is exposed throughout Co.Koa; Controllers, Bootstrap, Middleware, Models (and their) Validators, Services and middleware all have access to the Dependency Manager courtesy of the supplied $
parameter.
The Dependency Manager breaks down into 2 use categories:
- Dynamic Resources
- Static Resources
DynamicResources
The DependencyManager knows how to find Services, Models and Validators within their respective folders. the example below demonstrates the syntax:
const sampleService = $('SampleService'); // load an instance of SampleService in ./api/services/SampleService.js
const Sample = $('Sample') // call a Mongoose model instance derived from the Sample schema in ./api/models/Sample.js
const SampleValidator = $('SampleValidator') // call a validator library for your mongoose instance from ./api/models/validators/SampleValidator.js
Adding Custom Dependencies to the Dependency Manager
as of @1.8.0, Co.Koa supports the use of custom dependencies via the Dependency Register within your project’s config.json. more information on custom dependencies can be found in the Config Documentation.
const yourDependencyHere = $('YourDependencyHere');
Static Resources
$(':async') | Exposes await/async-friendly .each() and .reduce() methods. |
$(':echo') | Exposes the echo-handler NPM module |
$(':builder') | returns the co-koa-core's builder tool for iterating through files. This is an invaluable tool for handling custom database implementations in your plugins. See the [index.js](https://github.com/jaysaurus/co-koa-mongoose-plugin/blob/master/index.js) of the co-koa-mongoose-plugin to get a feel for how it works. |
$(':enums') | returns ./api/Enums.js |
$(':tree') | returns a stack-tree algorithm that can be used to iterate through object trees. |
$(':html') $(':css') $(':img') $(':js') | returns an object containing the methods .stream(filename) (under the hood this employs fs.createReadStream()) and .loadURL(fileName). You can add more static assets to this list via the AssetConfig.js. |
more information on Static Resources can be found here