Hangfire - EntityFramework Core - Concurrency error


#1

A second operation started on this context before a previous operation completed. This is usually caused by different threads using the same instance of DbContext. For more information on how to avoid threading issues with DbContext, see https:\/\/go.microsoft.com\/fwlink\/?linkid=2097913.

Here is how I set up Hangfire & EF:

        services 
            .AddDbContext<PaymentContext>(options => options.UseNpgsql(connectionString),
                ServiceLifetime.Transient);

        services.AddHangfire(x => x.UseMemoryStorage());
        services.AddHangfireServer();

app.UseHangfireDashboard();
app.UseHangfireServer();

RecurringJob.AddOrUpdate(() => myService.ExecuteMyJob(), Cron.Minutely);

Where myService has been injected through the configure method, and the DbContext is injected into that class.