【发布时间】:2018-03-08 23:55:58
【问题描述】:
我正在尝试在我的 asp core 2.0 项目中使用 Quartz sheduker。 我使用 nuget 下载了 Quartz 3.0.4,之后我添加了 services.AddQuartz(new QuartezOptions {}); 到 Startup.cs 中的 ConfigureService 函数
我的 app.UseQuartz() 也有同样的问题
那就是 Startup.cs 现在的样子:
using AspProj.Map;
using Microsoft.Extensions.Configuration;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using Swashbuckle.AspNetCore.Swagger;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Quartz;
namespace AspProj
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<CacheDbContext>(opt => opt.UseSqlServer(Configuration.GetConnectionString("DB")));
services.AddScoped<CacheDbContext>();
services.AddMvc();
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new Info { Title = "API", Version = "v1" });
});
services.AddQuartz(new QuartezOptions { });
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
}
app.UseSwagger();
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "DbApi V1");
});
app.UseStaticFiles();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
app.UseQuartz();
}
}
}
我尝试通过 using 连接不同的 Quartz 命名空间,但是没有用。 我只是不断收到来自 Visual Studio 2017 的“IServiceCollection 不包含 AddQuartz 的定义”。
error screenshot 我找不到任何与我有同样问题的人的信息。 有人知道吗,我该如何解决这个问题?
【问题讨论】:
-
Quartz不实现AddQuartz功能来注入 Quartz。您可以使用New来初始化 Quartz 对象。你可以参考Quartz.NET Quick Start Guide。 -
Quartz的替代品可以Hosted Service
标签: c# asp.net-core-mvc quartz-scheduler asp.net-core-2.0 quartz