Configuration¶

Starting from version 1.4, GlobalConfiguration class is the preferred way to configure Hangfire. This is an entry point for a couple of methods, including ones from third-party storage implementations or other extensions. The usage is simple, just include Hangfire namespace in your application initialization class and discover extension methods for the GlobalConfiguration.Configuration property.

For example, in ASP.NET applications, you can place initialization logic to the Global.asax.cs file:

  1. using Hangfire;
  2.  
  3. public class MvcApplication : System.Web.HttpApplication
  4. {
  5. protected void Application_Start()
  6. {
  7. // Storage is the only thing required for basic configuration.
  8. // Just discover what configuration options do you have.
  9. GlobalConfiguration.Configuration
  10. .UseSqlServerStorage("<name or connection string>");
  11. //.UseActivator(...)
  12. //.UseLogProvider(...)
  13. }
  14. }

For OWIN-based applications (ASP.NET MVC, Nancy, ServiceStack, FubuMVC, etc.), place the configuration lines to the OWIN Startup class.

  1. using Hangfire;
  2.  
  3. [assembly: OwinStartup(typeof(Startup))]
  4. public class Startup
  5. {
  6. public void Configuration(IAppBuilder app)
  7. {
  8. GlobalConfiguration.Configuration.UseSqlServerStorage("<name or connection string>");
  9. }
  10. }

For other applications, place it somewhere before calling other Hangfire methods.

原文:

http://docs.hangfire.io/en/latest/configuration/index.html