Skip to content

Dependency Injection

FeroxFoxxo edited this page Feb 8, 2023 · 7 revisions

Introduction

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

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>, where G is the current class.

Example of dependency injection

// 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.

MQReawakened Wiki

Development

Developer Tutorials

System Protocols:

External Protocols (TO DO):

Entities (TO DO):

  • Init Data
  • Sync Events

Miscellaneous (TO DO):

  • Console Commands
  • Timers
  • XMLs
  • Web
Clone this wiki locally