[英]How to use Quartz.NET with ASP.NET Core Web Application?
在傳統的ASP.NET
應用程序中,我們(重新)intialize的Quartz.NET
在調度Application_Start
在處理器global.asax.cs
。 但我不知道在哪里編寫用於調度作業的代碼,因為ASP.NET
Core Web應用程序中沒有global.asax.cs
。 我應該把代碼放在Startup.cs
嗎?
在Startup.cs文件中,這與asp.net核心相同。
你甚至可以為IServiceCollection類創建一個extenion方法,以使代碼干凈,所以代碼應該看起來像
public void ConfigureServices(IServiceCollection services)
{
services.AddQuartz(new QuartezOptions {});
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
app.UseQuartz();
}
您可以使用ConfigureServices
或Configure
方法。 雖然Configure
方法主要用於配置HTTP請求管道,但好處是您可以直接使用IHostingEnvironment
(以及獲取配置設置)和ILoggerFactory
接口。 如果在Startup
類中創建相應的屬性,則可以使用ConfigureServices
方法訪問這些依賴項。
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.