Skip to main content

IMoBroPlugin

Each plugin must include exactly one class that extends the IMoBroPlugin interface.
This class represents the actual "plugin" and is automatically instantiated by the MoBro data service when the plugin is loaded.

To ensure MoBro can instantiate the plugin, the class must include a public constructor.
Dependencies or services can be injected through the constructor. Refer to In Depth: Using Services for more details.

Functions

The IMoBroPlugin interface defines a set of optional functions that a plugin can implement.
These functions are triggered automatically by the MoBro data service during specific stages of the plugin's lifecycle or in response to certain events, as described below.

info

Implementing these functions is optional. A plugin can be created without implementing any of them.

Init()

This function is invoked once during the plugin's initialization phase.
Any logic that needs to run after the constructor (especially longer-running operations) should be placed here.

tip

Init() is an ideal location for tasks such as:

  • Registering metrics
  • Updating metric values
  • Scheduling recurring tasks

By organizing these responsibilities, the main business logic (e.g., creating and updating metrics) remains separate from plugin creation (handled in the constructor).

Example

Plugin.cs
public class Plugin : IMoBroPlugin
{
private readonly IMoBroService _mobro;
private readonly IMoBroScheduler _scheduler;
private readonly IMoBroSettings _settings;

// Constructor with injected dependencies
public Plugin(IMoBroService mobro, IMoBroScheduler scheduler, IMoBroSettings settings)
{
_mobro = mobro;
_scheduler = scheduler;
_settings = settings;
}

// Initialization logic
public void Init()
{
// Create and register metrics
CreateAndRegisterMetrics();

// Set static metric values
SetStaticMetricValues();

// Retrieve update frequency setting value
var updateFrequencySetting = _settings.GetValue<int>("update_frequency");

// Schedule recurring task to update dynamic metrics
_scheduler.Interval(UpdateDynamicMetrics, TimeSpan.FromSeconds(updateFrequencySetting), TimeSpan.FromSeconds(5));
}

[...]
}

InitAsync(): Task

This is the asynchronous version of the Init function. Use it when initialization involves asynchronous operations.


Shutdown()

The Shutdown() function is called to notify the plugin that it is about to be terminated.
This is the place to implement any cleanup actions or final tasks before the plugin shuts down.


ShutdownAsync(): Task

This is the asynchronous version of the Shutdown function. Use it for cleanup tasks that require asynchronous operations.