-
Notifications
You must be signed in to change notification settings - Fork 0
Autowire
The autowire module is a simple way to automatically register and intialise your controllers, services, tasks, fibres, etc.
The autowire module will scan for .ts
files in your /src
folder on
bootup (if enabled) and will attempt to import, register and initialise them,
currently plugins must be registered manually due to the differences in the
way they are handled.
Autowire will attempt to load the exported classes from the file, this will
consist of loading the default
or the first available class exported from
the file, once done it will read any metadata on the class to determine if
firstly it's an engine module and then it will pass it to the engine's register
service which will register it with the engine.
To enable autowiring, simply define autowire: true
in your engine config,
see below:
import { Engine } from '@symbux/turbo';
const engine = new Engine({
autowire: true,
...
});
If you decide not to use autowire please be aware that providers may not be available as they will need to be manually imported.
Sometimes you may not want autowire to scan all folders in your /src
folder, to
do this, you can define a list of folders to scan in your engine config, and then
tell the engine to only scan defined folders, to do this you do:
import { Engine } from '@symbux/turbo';
import { resolve } from 'path';
const engine = new Engine({
// ...
autowire: true,
scanFoldersOnly: true,
folders: [
resolve(__dirname, './src/controllers'),
],
// ...
});
Please be aware this will also affect the injection modules, because autowire scans
all folders in the project, it automatically loads all modules in the /src
into memory
which will trigger the DI module to pickup and register the modules, if you want to
use autowire to only scan a specific folder, you will need to define the providers in
the folders list, or import them directly like so:
import './some/path/to/some/provider';
- Controllers
- Middleware
- Autowire
- Plugins
- Tasks
- Fibres
- Authentication
- Registry
- Services
- Dependecy Injection
- Translations (i18n)
- Safe Quit
- Exception Handling
- Event Listener
- Custom Logger
- HTTP Plugin - Built-In
- WS Plugin - Built-In
- Discord Plugin - External
- Vite Plugin - External
- Inspect Plugin - External
- CLI Plugin - External
- Got an issue? Join our Discord
- Need your own plugin? Contact Me
- Have an idea? Let's Discuss
- Want to support me? Buy me a coffee