TickerQTickerQ
GuidesDefining Jobs

Constructor Injection

How TickerQ resolves dependencies for job classes.

TickerQ resolves job classes from DI on every execution. Standard constructor injection works automatically.

Single constructor

No special setup needed:

public class BillingJobs(IBillingService billing, ILogger<BillingJobs> logger)
{
    [TickerFunction("charge")]
    public async Task Charge(TickerFunctionContext ctx, CancellationToken ct)
        => await billing.ChargeAsync(ct);
}

Multiple constructors

Mark the one TickerQ should use with [TickerQConstructor]:

public class ReportJobs
{
    private readonly IReportService _reports;
    private readonly ILogger<ReportJobs>? _logger;

    public ReportJobs(IReportService reports)
        => _reports = reports;

    [TickerQConstructor]
    public ReportJobs(IReportService reports, ILogger<ReportJobs> logger)
    {
        _reports = reports;
        _logger = logger;
    }

    [TickerFunction("daily-report")]
    public async Task DailyReport(TickerFunctionContext ctx, CancellationToken ct)
        => await _reports.GenerateAsync(ct);
}

Rules

ScenarioResult
One constructorUsed automatically
Multiple, one [TickerQConstructor]Marked constructor used
Multiple, no attributeCompile warning — first constructor used
Multiple [TickerQConstructor]Compile error

On this page