Dependency Injection
Since version 2.0.0, dependency injection, thanks to iti, is a feature to customize your bot’s utilities and structures.
For example, a minimal setup for any project might look like this:
For any TypeScript project, you’ll need to add an interface to get intellisense and typings.
Full Example
Your full setup may have the following structure:
Directorysrc/
- index.ts (your main file and client)
- dependencies.d.ts (for intellisense)
Everything else is handled. However, you may want customize things.
Adding Dependencies to Root
Each sern built dependency must implement its contracts:
@sern/logger
: Logging data →Logging
@sern/errors
: Handling errors and lifetime →ErrorHandling
@sern/modules
: Managing all command modules →ModuleManager
@sern/emitter
: The key to emit events and occurences in a project →Emitter
You may also add disposers so that when the application crashes, the targeted dependency calls that function.
Init
-
Do you need to perform intializing behavor for a dependency?
-
Modify your
Dependencies
interface: -
Make sure its been added:
-
Now, when your bot starts, the
init
method will be called. 🎉