'.NET Core Worker service host as a Windows Services (using Coravel for task scheduling)

I have created a worker service to schedule a task using Coravel is a .NET Standard library and it is working as expected. I want to host the same as a windows service.

Host.CreateDefaultBuilder(args)
            .UseWindowsService()
                .ConfigureServices((hostContext, services) =>
                {
                    services.AddScheduler();
                    services.AddHostedService<Worker>(); //background service
                }

But i am using Corvel Invocable so is there any way i can achieve the same to host as a windows service? like:

public static void Main(string[] args)
        {
            IHost host = CreateHostBuilder(args).Build();
            host.Services.UseScheduler(scheduler =>
            {
                scheduler.Schedule<CsvGenerationInvocable>().EveryMinute();
            });
            host.Run();
        }



public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
            .UseWindowsService()
                .ConfigureServices((hostContext, services) =>
                {
                    services.AddScheduler();
                    services.AddHostedService<CsvGenerationInvocable>(); // Error no implicit conversion to IHostedService
                 }

Corval Invokable :

 public class CsvGenerationInvocable : IInvocable
        {
public async Task Invoke()
        {
           //Logic
        }
        }


Solution 1:[1]

You need to also inherit Background service to your Invokable class.

 public class CsvGenerationInvocable : BackgroundService, IInvocable
        {
public async Task Invoke()
        {
           //Logic
        }
        }

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Taktical1