gpt4 book ai didi

c# - IServiceCollection 不包含 AddQuartz 的定义

转载 作者:行者123 更新时间:2023-12-05 03:06:31 24 4
gpt4 key购买 nike

我正在尝试在我的 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 命名空间,这应该有效:

使用 quartz ;

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

dotnet 添加包 Quartz.Extensions.Hosting

关于c# - IServiceCollection 不包含 AddQuartz 的定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49184490/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com