Dependency Injection with Sitecore 9 Scheduling
source link: https://blog.coates.dk/2019/09/24/dependency-injection-with-sitecore-9-scheduling/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Dependency Injection with Sitecore 9 Scheduling
With this post I hope to draw attention to the ability to use dependency injection with Sitecore’s Scheduling Agents, for more information about agents see Johns blog post.
Most solutions now use DI with MVC controllers which is great, but I have noticed it is not used with agents?
Which is a pity as it is very simple to do this in Sitecore 9.0, Just add resolve =”true”.
Then add any dependencies to your constructor as required.
private
readonly
ILogger _logger;
private
readonly
UpdateSeatAvailabilityService _updateSeatAvailabilityService;
public
UpdateSeatAvailabilityAgent(
[NotNull]ILogger logger,
[NotNull]UpdateSeatAvailabilityService updateSeatAvailabilityService)
{
Assert.ArgumentNotNull(logger, nameof(logger));
Assert.ArgumentNotNull(updateSeatAvailabilityService, nameof(updateSeatAvailabilityService));
_logger = logger;
_updateSeatAvailabilityService = updateSeatAvailabilityService;
}
Hope this helps, Alan
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK