Services
Bu içerik henüz dilinizde mevcut değil.
You need some way to use dependencies in your command module. Services to the rescue!
Special Dependencies
Some keys in Dependencies
are special and are used by sern internally:
@sern/client
: Your Discord client. →Emitter
@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
Usage
Lets try to access the client you provided.
Safety
Services cannot be called in other services while makeDependencies
is forming.
For example, let’s pass a logger into our database:
Example
This is a code smell anyway. It breaks encapsulation and defeats the purpose of wiring dependencies
Another Example
Important
- Services can only be used after sern has made dependencies.
→ Calling a service before will crash your application. - Services can be safely used outside of a
commandModule
.
→ Be careful to not cause too many side effects. - You will need to wire dependencies together.
→ This is a good practice to keep your code clean. - Services can only be used after sern has made dependencies.
→ Calling a service before will crash your application. - Services can be safely used outside of a
commandModule
.
→ Be careful to not cause too many side effects.
Related API
- Use
Service
for single dependency. - Use
Services
for multiple dependencies.