Skip to main content

Assembly Discovery

JobMaster finds your handlers, static schedule profiles, schedule attributes ([NaturalCronSchedule], …) and job definitions by scanning the assemblies your app has loaded.

.NET loads an assembly only when your code uses one of its types. A project reference alone isn't enough: a library your app references but never names in code is never loaded, so JobMaster doesn't see what's in it.

When It Happens​

Typically when jobs live in their own project:

  • a worker service that only runs the handlers of a Billing.Jobs library, without using any of its types itself;
  • static schedule profiles, or handlers with schedule attributes, kept in a separate project.

What you'll see:

  • Static schedules aren't created, without any error: the profiles and schedule attributes in the library are never found.
  • Jobs for those handlers never run on that app.

The Fix​

Tell JobMaster which assemblies to add, by naming one type from each:

builder.Services.JobMasterAssemblyDiscovery()
.AddAssemblyContaining<BillingProfile>();

builder.Services.AddJobMasterCluster(config => { ... });
  • Any type of the library works (a handler, a profile, a marker class); naming it loads the assembly.
  • It can be called before or after AddJobMasterCluster, as many times as needed.
  • AddAssembly(assembly) and AddAssemblies(...) take assemblies directly, for example ones you load yourself.
  • The handlers found this way are registered in DI like any other; a handler you registered yourself is kept.

Add it in every app that needs the library's types: the apps that run its handlers, and the ones that declare its static schedules.