![]() ![]() Services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1) Services.AddQuartz(typeof(ScheduledJob)) Public async Task Execute(IJobExecutionContext context) Public ScheduledJob(IConfiguration configuration, ILogger logger) Private readonly IConfiguration configuration For this we need to implement Quartz.IJob interface in our job class. We first need to write our task, the unit of code which will be executed on a specific schedule. > dotnet add package Quartz -version 3.0.6 Dependency injection setupĪs ASP.NET Core has out of the box dependency injection support, we need to setup our resolvers in the startup, but before we do that we need to write our implementation of some of the Quartz interfaces we are going to use to setup the scheduled task in our project. I will use NuGet package manager since I am using Visual Studio 2017 Community edition. ![]() Since we will not focus on the actual response from the endpoint, but rather on the Startup.cs dependency injection part and the middleware, default WebApi project template is just fine.Īs a first step we need to add Quartz NuGet package to our project. I am using simple ASP.NET Core WebApi project template as a base for the example project. In this article I will try try to explain simple schedule of a background worker scheduled task using Quartz in ASP.NET Core application. Because of the ASP.NET Core architecture and out of the box middleware support it is a bit different to use it in a. Quartz is well supported and cross platform library for scheduling tasks inside your application. NET but you can always rely on out of the box libraries like Quartz. Another approach that I prefer is to create a scheduled cache refresh with the background worker which periodically refreshes the cache. You can use various approaches to refresh data including expiry, but this can create potential bottle necks in your application since once data expires, you will use request thread to pull the data, cache and serve the request response back. Of course this data has to be periodically refreshed. Caching common data like lookups for example in memory of your app can increase significantly your MVC web application performances and response time. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |