I stumbled upon some article mentioning it being possible to use dependency injection for scheduled jobs - great! But using the ScheduledPlugin attribute is dependent an Execute method which is static. How am I suppose to reach my instance member from the static method?
[ScheduledPlugIn(GUID = "7CFBA546-6015-43C7-94AB-FB73DCF8A960")]
public class CustomJob
private readonly IContentLoader _contentLoader;
public CustomJob(IContentLoader contentLoader)
_contentLoader = contentLoader;
public static string Execute()
// How can I reach my _contentLoader?
You can use the ServiceLocator in those cases
var repo = ServiceLocator.Current.GetInstance<IContentRepository>();
Scheduled Job classes should inherit ScheduledJobBase which has an overridable method public override string Execute() which isn't static. Then you can use constructor injection as usual.
Here is the start of one of mine as example
DisplayName = "Completed Order Export",
Description = "Sends queued completed commerce orders to the back-office systems",
GUID = JobGuidConstants.OrderExportJobId,
SortIndex = JobOrderingConstants.OrderExportJobSortIndex
public class OrderExportJob : ScheduledJobBase
private readonly INotificationManager _notificationManager;
private readonly IOrderProcessor _orderProcessor;
/// <param name="notificationManager">Notification manager</param>
/// <param name="orderProcessor">The order processor</param>
public OrderExportJob(INotificationManager notificationManager, IOrderProcessor orderProcessor)
_notificationManager = notificationManager;
_orderProcessor = orderProcessor;
/// Execute the job
public override string Execute()
As documented here https://world.episerver.com/documentation/developer-guides/CMS/scheduled-jobs/
It's also good practice to implement the Stop method too and make sure you're code can be stopped. I personally use Async methods and cancellation tokens for mine
Di friendly jobs were introduced long time ago - https://blog.tech-fellow.net/2016/12/28/scheduled-jobs-updates/. Avoid static and you'll be good.
@Daniel - you owe me beer now because of keywords you mentioned! :)