2
votes

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?

1
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. – Edward
alternative to Quartz could by Hosted Service – Lukas Kubis

1 Answers

3
votes

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