IServiceCollection不包含AddQuartz的定义

时间:2018-03-08 23:55:59

标签: c# asp.net-core-mvc quartz-scheduler asp.net-core-2.0 quartz

我试图在我的asp核心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();
    }
}

}

我尝试通过使用连接不同的Quartz命名空间,但它没有用。 我只是继续得到&#34; IServiceCollection不包含AddQuartz的定义&#34;来自visual studio 2017。

error screenshot 我无法找到与我有同样问题的人的任何信息。 sombody知道吗,我该如何解决这个问题?

1 个答案:

答案 0 :(得分:2)

尝试在您的依赖项中添加 Quartz 命名空间,这应该可以工作:

using Quartz;

还要确保安装了正确的软件包:

dotnet add package Quartz.Extensions.Hosting