2016-10-16 33 views
2

従来のASP.NETアプリケーションでは、Application_StartハンドラのQuartz.NETスケジューラをglobal.asax.csに(再)初期化しました。 しかし、global.asax.csASP.NETコアWebアプリケーションにないので、スケジューリングジョブのコードを書く場所はありません。 Startup.csにコードを入力する必要がありますか?Quartz.NETをASP.NETコアWebアプリケーションで使用するには?

答えて

1

ConfigureServicesまたはConfigureの方法を使用できます。 Configureメソッドは、主にHTTPリクエストパイプラインを設定するために使用されますが、IHostingEnvironment(したがって設定を取得する)とILoggerFactoryインターフェイスを直接使用できるという利点があります。 ConfigureServicesメソッドを使用すると、Startupクラスに対応するプロパティを作成すると、それらの依存関係にアクセスできます。

// 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) 
2

Startup.csファイルでは、これはasp.net coreと同等です。

あなたも、コードをきれいにするためにIServiceCollectionクラスのextenionメソッドを作成することができますので、コードは

public void ConfigureServices(IServiceCollection services) 
{ 
    services.AddQuartz(new QuartezOptions {}); 
} 

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) 
{ 
    app.UseQuartz(); 
} 
のようになります。
関連する問題