public static IApplicationBuilder UseHangfireServer( [NotNull] this IApplicationBuilder app, [CanBeNull] BackgroundJobServerOptions options = null, [CanBeNull] IEnumerable <IBackgroundProcess> additionalProcesses = null, [CanBeNull] JobStorage storage = null) { if (app == null) { throw new ArgumentNullException(nameof(app)); } HangfireServiceCollectionExtensions.ThrowIfNotConfigured(app.ApplicationServices); var services = app.ApplicationServices; var lifetime = services.GetRequiredService <IApplicationLifetime>(); storage = storage ?? services.GetRequiredService <JobStorage>(); options = options ?? services.GetService <BackgroundJobServerOptions>() ?? new BackgroundJobServerOptions(); additionalProcesses = additionalProcesses ?? services.GetServices <IBackgroundProcess>(); options.Activator = options.Activator ?? services.GetService <JobActivator>(); options.FilterProvider = options.FilterProvider ?? services.GetService <IJobFilterProvider>(); options.TimeZoneResolver = options.TimeZoneResolver ?? services.GetService <ITimeZoneResolver>(); var server = HangfireServiceCollectionExtensions.GetInternalServices(services, out var factory, out var stateChanger, out var performer) #pragma warning disable 618 ? new BackgroundJobServer(options, storage, additionalProcesses, null, null, factory, performer, stateChanger) #pragma warning restore 618 : new BackgroundJobServer(options, storage, additionalProcesses); lifetime.ApplicationStopping.Register(() => server.SendStop()); lifetime.ApplicationStopped.Register(() => server.Dispose()); return(app); }
public static IApplicationBuilder UseHangfireDashboard( [NotNull] this IApplicationBuilder app, [NotNull] string pathMatch = "/hangfire", [CanBeNull] DashboardOptions options = null, [CanBeNull] JobStorage storage = null) { if (app == null) { throw new ArgumentNullException(nameof(app)); } if (pathMatch == null) { throw new ArgumentNullException(nameof(pathMatch)); } HangfireServiceCollectionExtensions.ThrowIfNotConfigured(app.ApplicationServices); var services = app.ApplicationServices; storage = storage ?? services.GetRequiredService <JobStorage>(); options = options ?? services.GetService <DashboardOptions>() ?? new DashboardOptions(); options.TimeZoneResolver = options.TimeZoneResolver ?? services.GetService <ITimeZoneResolver>(); var routes = app.ApplicationServices.GetRequiredService <RouteCollection>(); app.Map(new PathString(pathMatch), x => x.UseMiddleware <AspNetCoreDashboardMiddleware>(storage, options, routes)); return(app); }
public static IEndpointConventionBuilder MapHangfireDashboard( [NotNull] this IEndpointRouteBuilder endpoints, [NotNull] string pattern, [CanBeNull] DashboardOptions options = null, [CanBeNull] JobStorage storage = null) { if (endpoints == null) { throw new ArgumentNullException(nameof(endpoints)); } if (pattern == null) { throw new ArgumentNullException(nameof(pattern)); } var app = endpoints.CreateApplicationBuilder(); HangfireServiceCollectionExtensions.ThrowIfNotConfigured(app.ApplicationServices); var services = app.ApplicationServices; storage = storage ?? services.GetRequiredService <JobStorage>(); options = options ?? services.GetService <DashboardOptions>() ?? new DashboardOptions(); options.TimeZoneResolver = options.TimeZoneResolver ?? services.GetService <ITimeZoneResolver>(); var routes = app.ApplicationServices.GetRequiredService <Dashboard.RouteCollection>(); var pipeline = app .UsePathBase(pattern) .UseMiddleware <AspNetCoreDashboardMiddleware>(storage, options, routes) .Build(); return(endpoints.Map(pattern + "/{**path}", pipeline)); }