Nomirun Host can automatically register hosted services from your modules, that implements INomirunBackgroundService
interface.
Below is an example of a background job service, that you can put into the module and it will be automatically registered with the host.
public class DemoWorker : BackgroundService, INomirunBackgroundService
{
private readonly ILogger<DemoWorker> _logger;
public DemoWorker(ILogger<DemoWorker> logger)
{
_logger = logger;
}
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
while (!stoppingToken.IsCancellationRequested)
{
_logger.LogInformation("DemoWorker running at: {time}", DateTimeOffset.Now);
await Task.Delay(1000, stoppingToken);
}
}
}