Skip to main content

Using Services

The MoBro Plugin SDK provides several services designed to simplify common tasks in a data plugin, such as managing settings or implementing recurring tasks to poll sensor values.

Dependency Injection

You can easily inject any service offered by the MoBro Plugin SDK into the plugin's constructor as demonstrated below:

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

public Plugin(IMoBroService mobro, IMoBroScheduler scheduler, IMoBroSettings settings, ILogger logger)
{
_mobro = mobro;
_scheduler = scheduler;
_settings = settings;
_logger = logger;
}

[...]
}
note

The plugin constructor must be public for MoBro to instantiate it successfully.

Injectable Services

The following interfaces are currently supported for dependency injection into the plugin's constructor:

  • IMoBroService:
    Enables plugins to interact with MoBro by registering items, updating metric values, and more.
  • IMoBroSettings:
    Provides access to plugin settings values.
  • IMoBroScheduler:
    A scheduler that facilitates the implementation of recurring tasks, such as polling sensor values or querying external APIs.
  • ILogger:
    An instance of Microsoft.Extensions.Logging.ILogger to be used for logging within the plugin.
  • IMoBroFileManager:
    Allows plugins to easily manage files.
  • IMoBroPersistenceManager:
    Simplifies the serialization and persistence of arbitrary objects for plugins.