Skip to content

imclint21/circle

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Circle

About Circle

.Net Core 3 Manager Background Service.

Introduction

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.

Startup.cs

public void ConfigureServices(IServiceCollection services)
{
    services.AddCircle(options =>
    {
        options.Period = TimeSpan.FromSeconds(5);
        options.UseHandler<Work>();
    });
}

Create a Job

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!");
    }
}

Control the Job

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();
  }
}