Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hangfireio/hangfire.aspnet
Recommended way to install Hangfire for ASP.NET applications hosted in IIS to make transition to always-running mode simpler
https://github.com/hangfireio/hangfire.aspnet
Last synced: 5 days ago
JSON representation
Recommended way to install Hangfire for ASP.NET applications hosted in IIS to make transition to always-running mode simpler
- Host: GitHub
- URL: https://github.com/hangfireio/hangfire.aspnet
- Owner: HangfireIO
- License: mit
- Created: 2016-06-09T12:55:48.000Z (over 8 years ago)
- Default Branch: main
- Last Pushed: 2024-03-22T10:27:04.000Z (10 months ago)
- Last Synced: 2024-12-21T15:06:48.511Z (12 days ago)
- Language: C#
- Homepage:
- Size: 8.89 MB
- Stars: 94
- Watchers: 15
- Forks: 40
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Hangfire.AspNet
[![GitHub release](https://img.shields.io/github/release/HangfireIO/Hangfire.AspNet.svg)](https://github.com/HangfireIO/Hangfire.AspNet/releases)
[![Build status](https://ci.appveyor.com/api/projects/status/ywkl7xx1022odi7m?svg=true)](https://ci.appveyor.com/project/hangfireio/hangfire-aspnet)This package provides recommended way to install Hangfire to ASP.NET applications hosted in IIS with later transition to always-running mode in mind. It contains classes and methods that use `IRegisteredObject` and `IProcessHostPreloadClient` interfaces to plug in to the IIS and ASP.NET application lifecycle more tightly than regular OWIN methods available in the `Hangfire.Core` package.
The package also includes a Powershell script to enable Always Running mode for your application that is based on Service Autostart Providers.
The package aims to replace the documentation article [Making ASP.NET application always running](https://docs.hangfire.io/en/latest/deployment-to-production/making-aspnet-app-always-running.html).
## Installation
This project is available as a NuGet Package:
```powershell
Install-Package Hangfire.AspNet
```## Usage
The package simplifies Hangfire configuration when an application has multiple startup paths, e.g. when using the autostart providers feature to make a web application always running as [described here](https://docs.hangfire.io/en/latest/deployment-to-production/making-aspnet-app-always-running.html).
We define a configuration method, and point Hangfire.AspNet to it from each startup point. Hangfire.AspNet will ensure it is called only once, so we have Hangfire initialized if any startup point is triggered.
```csharp
public class Startup
{
public static IEnumerable GetHangfireConfiguration()
{
// Calling configuration as a first step
GlobalConfiguration.Configuration
.SetDataCompatibilityLevel(CompatibilityLevel.Version_180)
.UseSimpleAssemblyNameTypeSerializer()
.UseRecommendedSerializerSettings()
.UseSqlServerStorage("connection_string");// And then creating background job servers, either one or multiple
yield return new BackgroundJobServer();
}public void Configuration(IAppBuilder app)
{
// Initializing from a regular web application startup, including
// the developer workflow.
app.UseHangfireAspNet(GetHangfireConfiguration);
app.UseHangfireDashboard();
}
}
``````csharp
public class ApplicationPreload : IProcessHostPreloadClient
{
public void Preload(string[] parameters)
{
// Pointing the same configuration from the Startup class,
// and Hangfire.AspNet will ensure that it is called only
// once.
// This method will be triggered by autostart providers
// feature as described in the article referenced above.
HangfireAspNet.Use(Startup.GetHangfireConfiguration);
}
}
```