.Net Core 3 Manager Background Service.
Circle is a .Net Core 3 Manager Background Service, that expose an API to handle it.
You simply need to add AddCircle()
in the services collection.
public void ConfigureServices(IServiceCollection services)
{
services.AddCircle(options =>
{
options.Period = TimeSpan.FromSeconds(5);
options.UseHandler<Work>();
});
}
You need to create a new class that inherits from IWorkHandler
, and write the task that need to be executed.
public class Work : IWorkHandler
{
public void DoWork()
{
Console.WriteLine("Test!");
}
}
You can use CircleControl
class to start, stop or restart the service.
public class HomeController : Controller
{
private readonly CircleControl _circle;
public HomeController(CircleControl circle)
{
_circle = circle;
}
public IActionResult Stop()
{
_circle.Stop();
return Ok();
}
}