DKNet

Register startup tasks

Part of DKNet.AspCore.Tasks. Implement IBackgroundTask.RunAsync(CancellationToken) and register each implementation explicitly or scan named assemblies:

using DKNet.AspCore.Tasks;
using Microsoft.Extensions.DependencyInjection;
var services = new ServiceCollection();
services.AddBackgroundJob<PrintTask>();
services.AddBackgroundJobFrom([typeof(PrintTask).Assembly]);
Console.WriteLine(services.Count(d => d.ServiceType == typeof(IBackgroundTask))); // 1

public sealed class PrintTask : IBackgroundTask
{
    public Task RunAsync(CancellationToken cancellationToken = default)
        => Task.CompletedTask;
}

Explicit registration and assembly scanning share an implementation-type duplicate guard and register one BackgroundJobHost.

TaskSetups lives in Microsoft.Extensions.DependencyInjection. Both methods add one internal hosted BackgroundJobHost. Each task is registered as scoped IBackgroundTask, deduplicated by service type plus implementation type. Scanning selects nonabstract classes assignable to IBackgroundTask from the supplied assemblies.

⚙️ Configuration reference

Input Type Default Effect
TJob class, IBackgroundTask required Registers one task implementation.
assemblies Assembly[] required Supplies scanning scope; this is not a params argument.

There is no options object or configuration section.

⚠️ Gotchas & limits