【问题标题】:IServiceCollection does not contain definition for AddQuartzIServiceCollection 不包含 AddQuartz 的定义
【发布时间】: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 我找不到任何与我有同样问题的人的信息。 有人知道吗,我该如何解决这个问题?

【问题讨论】:

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


【解决方案1】:

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

using Quartz;

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

dotnet add package Quartz.Extensions.Hosting

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-06-09
    • 2022-01-03
    • 1970-01-01
    • 2020-04-02
    • 2019-04-14
    • 2016-09-25
    • 2020-08-20
    • 1970-01-01
    相关资源
    最近更新 更多