Refactor hostedServices into background jobs (#14291)
* Refactor jobs from HostedServices into BackgroundJobs
* Clean up generics and DI setup
* Add RecurringBackgroundJob Unit Tests
* Add ServiceCollection helper
* Add Obsolete attributes
* Add Notification Classes
* Add UnitTests for RecurringBackgroundJob HostedService
* Add NotificationEvents
* Add state to notifications
* Update UnitTests
* Add Obsolete Attributes to old hosted service classes
* Updated xmldoc in IRecurringBackgroundJob.cs
* Update Obsolete attribute messages to indicate classes will be removed in Umbraco 14
(cherry picked from commit c30ffa9ac3)
This commit is contained in:
committed by
Bjarke Berg
parent
1d43a67934
commit
04ac1542aa
@@ -0,0 +1,31 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
using Umbraco.Cms.Core.Composing;
|
||||
using Umbraco.Cms.Infrastructure.BackgroundJobs;
|
||||
|
||||
namespace Umbraco.Extensions;
|
||||
|
||||
public static class ServiceCollectionExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Adds a recurring background job with an implementation type of
|
||||
/// <typeparamref name="TJob" /> to the specified <see cref="IServiceCollection" />.
|
||||
/// </summary>
|
||||
public static void AddRecurringBackgroundJob<TJob>(
|
||||
this IServiceCollection services)
|
||||
where TJob : class, IRecurringBackgroundJob =>
|
||||
services.AddSingleton<IRecurringBackgroundJob, TJob>();
|
||||
|
||||
/// <summary>
|
||||
/// Adds a recurring background job with an implementation type of
|
||||
/// <typeparamref name="TJob" /> using the factory <paramref name="implementationFactory"/>
|
||||
/// to the specified <see cref="IServiceCollection" />.
|
||||
/// </summary>
|
||||
public static void AddRecurringBackgroundJob<TJob>(
|
||||
this IServiceCollection services,
|
||||
Func<IServiceProvider, TJob> implementationFactory)
|
||||
where TJob : class, IRecurringBackgroundJob =>
|
||||
services.AddSingleton<IRecurringBackgroundJob, TJob>(implementationFactory);
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user