IServiceCollection does not contain definition for AddQuartz
Asked Answered
P

2

7

I'm trying to use Quartz sheduker in my asp core 2.0 project. I downloaded Quartz 3.0.4 using nuget and after that i added services.AddQuartz(new QuartezOptions {}); to ConfigureService function in Startup.cs

I also have the same problem with app.UseQuartz()

Thats, how Startup.cs is looking now:

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();
    }
}

}

I tried to connect different Quartz namespaces through using, but it has no use. I just keep getting "IServiceCollection does not contain definition for AddQuartz" from visual studio 2017.

error screenshot I cant find any information about someone with the same problem as me. Did sombody knows, how can i fix this?

Peninsula answered 8/3, 2018 at 23:55 Comment(2)
Quartz do not implement the AddQuartz feature to inject the Quartz. You could use New to initlize Quartz object. You could refer Quartz.NET Quick Start Guide.Churinga
alternative to Quartz could by Hosted ServiceRubdown
W
14

Try to add the Quartz namespace in your dependencies and this should work:

using Quartz;

Also ensure that the proper package has been installed:

dotnet add package Quartz.Extensions.Hosting

Whiggism answered 10/1, 2021 at 2:27 Comment(0)
N
1

need to install package Quartz.NET Microsoft.Extensions.DependencyInjection

Nailbiting answered 9/8, 2022 at 2:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.