Hangfire.EntityFrameworkCore
0.7.0
dotnet add package Hangfire.EntityFrameworkCore --version 0.7.0
NuGet\Install-Package Hangfire.EntityFrameworkCore -Version 0.7.0
<PackageReference Include="Hangfire.EntityFrameworkCore" Version="0.7.0" />
paket add Hangfire.EntityFrameworkCore --version 0.7.0
#r "nuget: Hangfire.EntityFrameworkCore, 0.7.0"
// 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
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 | Versions 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. |
-
.NETStandard 2.0
- Hangfire.Core (>= 1.8.0 && < 2.0.0)
- Microsoft.EntityFrameworkCore.Relational (>= 3.1.0)
-
net8.0
- Hangfire.Core (>= 1.8.0 && < 2.0.0)
- Microsoft.EntityFrameworkCore.Relational (>= 8.0.0)
-
net9.0
- Hangfire.Core (>= 1.8.0 && < 2.0.0)
- Microsoft.EntityFrameworkCore.Relational (>= 9.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
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.