-
Notifications
You must be signed in to change notification settings - Fork 15
Dependency Injection
MQReawakened is bundled with a very barebones dependency injection service. It is recommended that you use DI when writing your modules.
In the constructor of your code, any parameters will be filled in by the global IServiceProvider.
Any publicly settable properties will also be filled in the same manner, if the class is an entity or protocol.
The Init project is the entrance of the program. It is where all modules are created and injected into all of their respective classes, and where the server starts up.
The following cases will be injected through the service provider, as they are loaded up through reflection. These are commonly injected in the Server
, Reawakened
, and AssetBundles
module classes, through the AddServices
overridden method. Others not listed are added on an individual basis, and are directly specified in their related module.
- If it implements
IService
. - If it implements
IConfig
. - If it implements
IEventSink
. - If it implements
IBundledXml
. - If it extends
ThriftHandler
. - If it extends
Module
. - The
IServiceProvider
. - The
ILogger<G>
, whereG
is the current class.
// Injection via constructor
public class XXX : IService
{
private readonly YYY _yyy;
public XXX(YYY yyy)
{
_yyy = yyy;
}
}
// Injection via properties (ONLY WORKS FOR ENTITIES AND PROTOCOLS)
public class XXX : ExternalProtocol
{
public YYY Yyy { get; set; }
}
It is preferred to use property injection where applicable.
- Setting up the development environment
- Getting started with dependency injection
- Creating your first pull request
- Troubleshooting
- Creating An Issue
- Init Data
- Sync Events
- Console Commands
- Timers
- XMLs
- Web