AppBuilderExtensions Class |
Namespace: Hangfire
Name | Description | |
---|---|---|
UseHangfireDashboard(IAppBuilder) |
Adds Dashboard UI middleware to the OWIN request processing pipeline under
the /hangfire path, for the Current storage.
| |
UseHangfireDashboard(IAppBuilder, String) |
Adds Dashboard UI middleware to the OWIN request processing pipeline under
the given path, for the Current storage.
| |
UseHangfireDashboard(IAppBuilder, String, DashboardOptions) |
Adds Dashboard UI middleware to the OWIN request processing pipeline under
the specified path and the given options, for the Current
storage.
| |
UseHangfireDashboard(IAppBuilder, String, DashboardOptions, JobStorage) |
Adds Dashboard UI middleware to the OWIN request processing pipeline with the
specified parameters.
| |
UseHangfireServer(IAppBuilder) |
Creates a new instance of the BackgroundJobServer class
with default options and Current storage and
registers its disposal on application shutdown.
| |
UseHangfireServer(IAppBuilder, BackgroundJobServerOptions) |
Creates a new instance of the BackgroundJobServer class
with the specified options and Current storage,
and registers its disposal on application shutdown.
| |
UseHangfireServer(IAppBuilder, IBackgroundProcess) |
Creates a new instance of the BackgroundJobServer class
with the given collection of additional background processes and
Current storage, and registers its disposal
on application shutdown.
| |
UseHangfireServer(IAppBuilder, BackgroundJobServerOptions, JobStorage) |
Creates a new instance of the BackgroundJobServer class
with the given options and specified storage, and registers its disposal
on application shutdown.
| |
UseHangfireServer(IAppBuilder, BackgroundJobServerOptions, IBackgroundProcess) |
Creates a new instance of the BackgroundJobServer class
with the specified options, given collection of background processes
and Current storage, and registers its
disposal on application shutdown.
| |
UseHangfireServer(IAppBuilder, JobStorage, BackgroundJobServerOptions, IBackgroundProcess) |
Starts a new instance of the BackgroundJobServer class with
the given arguments, and registers its disposal on application shutdown.
|
This class simplifies Hangfire configuration in OWIN applications, please read Getting Started with OWIN and Katana if you aren't familiar with OWIN and/or don't know what is the Startup class.
The methods of this class should be called from OWIN's Startup class.
Dashboard UI contains pages that allow you to monitor almost every aspect of background processing. It is exposed as an OWIN middleware that intercepts requests to the given path.
OWIN implementation of Dashboard UI allows to use it outside of web applications, including console applications and Windows Services.
Important |
---|
By default, an access to the Dashboard UI is restricted only to local requests for security reasons. Before publishing a project to production, make sure you still have access to the Dashboard UI by using the Hangfire.Dashboard.Authorization package. |
In addition to creation of a new instance of the BackgroundJobServer class, these methods also register the call to its Dispose method on application shutdown. This is done via registering a callback on the corresponding CancellationToken from OWIN environment ("host.OnAppDisposing" or "server.OnDispose" keys).
This enables graceful shutdown feature for background jobs and background processes without any additional configuration.
Please see BackgroundJobServer for more details regarding background processing.
Basic setup in an OWIN application looks like the following example. Please note that job storage should be configured before using the methods of this class.
public void Configuration(IAppBuilder app) { GlobalConfiguration.Configuration .UseSqlServerStorage(@"<your_connection_string>"); app.UseHangfireServer(); app.UseHangfireDashboard(); }
If you want to install dashboard without starting a background job server, for example, to process background jobs outside of your web application, call only the UseHangfireDashboard Overload.
public void Configuration(IAppBuilder app) { // GlobalConfiguration usage was removed for clarity. app.UseHangfireDashboard(); }
By default, you can access Dashboard UI by hitting the http(s)://<app>/hangfire URL, however you can change it as in the following example.
public void Configuration(IAppBuilder app) { // GlobalConfiguration usage was removed for clarity. app.UseHangfireDashboard("/admin/hangfire"); }
The following example demonstrates how to change default local-requests-only authorization for Dashboard UI.
// Install the Hangfire.Dashboard.Authorization NuGet package first. public void Configuration(IAppBuilder app) { // GlobalConfiguration usage was removed for clarity. var options = new DashboardOptions { AuthorizationFilters = new [] { new AuthorizationFilter { Roles = "admin" }, } }; app.UseHangfireDashboard("/hangfire", options); }
Have you seen the Back to site button in the Dashboard? By default it leads you to the root of your site, but you can configure the behavior.
public void Configuration(IAppBuilder app) { // GlobalConfiguration usage was removed for clarity. var options = new DashboardOptions { AppPath = "/app" }; app.UseHangfireDashboard("/hangfire", options); }
The following example demonstrates adding multiple Dashboard UI endpoints. This may be useful when you are using multiple shards for your background processing needs.
public void Configuration(IAppBuilder app) { // GlobalConfiguration.UseStorage isn't necessary here, // because you are passing a storage instance explicitly. var storage1 = new SqlServerStorage(@"connection_string_1"); var storage2 = new SqlServerStorage(@"connection_string_2"); app.UseHangfireDashboard("/hangfire1", new DashboardOptions(), storage1); app.UseHangfireDashboard("/hangfire2", new DashboardOptions(), storage2); }