Hangfire.EntityFrameworkCore 0.7.0

dotnet add package Hangfire.EntityFrameworkCore --version 0.7.0                
NuGet\Install-Package Hangfire.EntityFrameworkCore -Version 0.7.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Hangfire.EntityFrameworkCore" Version="0.7.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Hangfire.EntityFrameworkCore --version 0.7.0                
#r "nuget: Hangfire.EntityFrameworkCore, 0.7.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Hangfire.EntityFrameworkCore as a Cake Addin
#addin nuget:?package=Hangfire.EntityFrameworkCore&version=0.7.0

// Install Hangfire.EntityFrameworkCore as a Cake Tool
#tool nuget:?package=Hangfire.EntityFrameworkCore&version=0.7.0                

Hangfire.EntityFrameworkCore

License MIT Latest version

Overview

An Entity Framework Core provider-neutral job storage implementation for Hangfire developed by Sergey Odinokov.

Installation

To install Hangfire Entity Framework Core Storage, run the following command in the Nuget Package Manager Console:

PM> Install-Package Hangfire.EntityFrameworkCore

ASP.NET

After installation, update your existing OWIN Startup with the following lines of code:

public void Configuration(IAppBuilder app)
{
    // Register Entity Framework Core Storage
    GlobalConfiguration.Configuration.UseEFCoreStorage(
        // Configure Entity Framework Core to connect database, e.g. SQL Server
        builder => builder.UseSqlServer("Data Source=(LocalDB)\\MSSQLLocalDB;Database=Hangfire"),
        // Optionally configure Entity Framework Core Storage
        new EFCoreStorageOptions()).
        // Optionally register database creator
        UseDatabaseCreator();

    // Configure Hangfire Server and/or Hangfire Dashboard
    app.UseHangfireServer();
    app.UseHangfireDashboard();
}

ASP.NET Core

There is an example to use Hangfire.EntityFrameworkCore with ASP.NET Core.

Migrations

Currently, automatic migrations are not implemented. The migrations support planned and will be implemented on future releases.

Using your own DbContext

As of the 0.3.0 version you have the ability to attach the tables required for this library to your own DbContext. Since the tables are attached to your own DbContext this means that the migrations are also attached to this DbContext and managed by the regular dotnet ef migration flow.

There is an example of this configuration found here, however the important sections are listed below.

In Program.cs:

var builder = WebApplication.CreateBuilder(args);
var connectionString = builder.Configuration.GetConnectionString("HangfireConnection")
    ?? throw new InvalidOperationException("Connection string 'HangfireConnection' not found.");

builder.Services.AddDbContextFactory<SampleDbContext>(builder => builder.UseSqlite(connectionString));
builder.Services.AddHangfire((serviceProvider, configuration) =>
    configuration.UseEFCoreStorage(
        () => serviceProvider.GetRequiredService<IDbContextFactory<SampleDbContext>>().CreateDbContext(),
        new EFCoreStorageOptions
        {
            CountersAggregationInterval = new TimeSpan(0, 5, 0),
            DistributedLockTimeout = new TimeSpan(0, 10, 0),
            JobExpirationCheckInterval = new TimeSpan(0, 30, 0),
            QueuePollInterval = new TimeSpan(0, 0, 15),
            Schema = string.Empty,
            SlidingInvisibilityTimeout = new TimeSpan(0, 5, 0),
        }));

And then in the OnModelCreating method of the DbContext class:

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
    base.OnModelCreating(modelBuilder);
    modelBuilder.OnHangfireModelCreating();
}

Queue providers

There is only built-in SQL-based internal queue provider supported. Additional providers support will be implemented in future.

License

Hangfire.EntityFrameworkCore licensed under the MIT License.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.7.0 791 1/22/2025
0.6.0 43,713 2/13/2024
0.5.0 62,678 11/30/2022
0.4.0 127,987 11/30/2021
0.3.1 35,943 4/21/2021
0.3.0 6,560 2/9/2021
0.2.0 1,140 11/10/2020
0.1.3 1,200 12/22/2019
0.1.2 1,101 9/28/2019
0.1.1 1,184 7/30/2019
0.1.0 1,345 3/18/2019

0.7.0
• Added – .NET 9 support.
• Added – External DbContext custom schema name support.
• Breaking – Remove `net6.0` target.
• Breaking – Remove `net7.0` target.
• Fixed - A few EFCoreFetchedJob behavior issues (by @typesbb).
• Fixed - ExpirationManager sometimes fails delete jobs with parameters.
• Fixed - Unexpected error if external DbContext uses EnableRetryOnFailure (by @davidscheidt2).
• Fixed - SQL parameter names colliding Oracle keywords (by @thegnu).

0.6.0
• Added – .NET 8 support (thanks to @m0ddixx).
• Breaking – Set minimal inclusive Hangfire.Core version 1.8.0.
• Breaking – Remove `netstandard2.1` target.

0.5.0
• Added – .NET 7 support.
• Breaking – Set minimum inclusive EFCore version 2.1.0.
• Changed – Make entity classes public.
• Fixed – Unexpected DbUpdateException on ExpirationManager execution.
• Fixed – Optimize ExpirationManager database traffic consumption.

0.4.0
• Added – .NET 6 support
• Changed – Set minimal inclusive Hangfire.Core version 1.7.0.
• Fixed – A few errors caused by EFCore 6.0 breaking changes.
• Fixed – Unexpected DbUpdateConcurrencyException on ExpirationManager execution.

0.3.1
• Changed – Increase database string fields max length up to 256 (by @jack775544).

0.3.0
• Added – External DbContext support (by @jack775544).

0.2.0
• Added – `netstandard2.1` target framework support.
• Added – .NET 5 support.
• Added – Source Link support.

0.1.3
• Fixed – An unexpected MissingMethodException by using another `EntityTypeBuilder.HasIndex` method overload existing in EFCore 3.0.

0.1.2
• Fixed – A few errors caused by EFCore 3 breaking changes.

0.1.1
• Changed – Set minimum inclusive EFCore version 2.0.0.
• Changed – Set maximum exclusive Hangfire.Core version 2.0.
• Fixed – Optimize storage monitoring statistics.

0.1.0
This is the first public release.