using System.Threading;
using System.Threading.Tasks;
namespace Microsoft.Extensions.Hosting
{
///
/// Wrapper class to start a background service.
///
/// The service type.
public class BackgroundServiceStarter : IHostedService
where TService : class, IHostedService
{
private readonly TService service;
///
/// Initializes an new instance of the class.
///
/// The service to work in background.
public BackgroundServiceStarter(TService backgroundService)
{
service = backgroundService;
}
///
/// Starts the service.
///
///
///
public Task StartAsync(CancellationToken cancellationToken)
{
return service.StartAsync(cancellationToken);
}
///
/// Stops the service.
///
///
///
public Task StopAsync(CancellationToken cancellationToken)
{
return service.StopAsync(cancellationToken);
}
}
}