Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

Hangfire Creation Table With EFCore

//////////// Program.cs ///////////////////////////

using Hangfire;
using Hangfire.EntityFrameworkCore;

var builder = WebApplication.CreateBuilder(args);

// adding your other services here 

builder.Services.AddDbContextFactory<DBContext>(options => options.UseNpgsql("Connection_String"));

builder.Services.AddHangfire((serviceProvider, configuration) =>
    configuration.UseEFCoreStorage(
        () => serviceProvider.GetRequiredService<IDbContextFactory<DBContext>>().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),
        }));

builder.Services.AddHangfireServer(options => options.WorkerCount = 1);

// your other code of Program.cs

//////////// DBContext.cs ///////////////////////////////

using Hangfire.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;

namespace EFCore;

public class DBContext : DbContext
{
    public DBContext(DbContextOptions<DBContext> options) : base(options)
    {
        
    }

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

PREVIOUS NEXT
Code Example
Csharp :: c# show hidden window wpf 
Csharp :: webtest fullscreen extend window maximize 
Csharp :: localhost ssl certificate error in visual studio 2022 .net 6 
Csharp :: blazor OnInitializedAsync Unhandled exception rendering component: Cannot wait on monitors on this runtime. 
Csharp :: c# linq where value is max and one item 
Csharp :: Show Form on Second Monitor 
Csharp :: c# class reference 
Csharp :: how to make projectile track and go to specified enemy in unity 
Csharp :: how to make a methode accessible from all the forms c# 
Csharp :: most popular products code using asp.net core in visual studio code 
Csharp :: C# program applies bonus points 
Csharp :: Transparent UserControl 
Csharp :: add getenumerator to class c# 
Csharp :: download file c# 
Csharp :: windows forms picturebox click event 
Csharp :: Delegate with parameter and return 
Csharp :: Read from textfile and fill in textbox 
Csharp :: secret 
Csharp :: android.content.res.Resources_Delegate.throwException(Resources_Delegate.java:1145) 
Csharp :: c# stack 
Csharp :: unity how to get data of play session time in a text file? 
Csharp :: C# listview as listbox 
Csharp :: unity reload script assemblies 
Csharp :: unity event trigger 
Csharp :: c# form 
Csharp :: @razor identify last foreach 
Csharp :: get file id from mongodb without objectid using c# 
Csharp :: population of the world 
Html :: espacio html 
Html :: open phone from anchor tag 
ADD CONTENT
Topic
Content
Source link
Name
2+3 =