[Feature] REST API Endpoint
This commit is contained in:
@@ -1,2 +1,10 @@
|
||||
# TemplateNETService
|
||||
|
||||
Template for windows service based on .net 8 with the following features:
|
||||
- Log with Serilog
|
||||
- Example to extract configuration settings from appsettings.json and safe in static class "Config"
|
||||
- OnStart & OnStop functions (File: BaseWorker.cs)
|
||||
- Batch files to install / delete service
|
||||
- Example for an API-Endpoint: api/ping (File: ServiceController.cs)
|
||||
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TemplateNETService.Business;
|
||||
|
||||
namespace TemplateNETService
|
||||
{
|
||||
@@ -12,7 +13,7 @@ namespace TemplateNETService
|
||||
{
|
||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||
{
|
||||
Log.Debug("Der Service wurde gestartet.");
|
||||
Log.Debug($"Service is started on port {Config.general.ThisPort}...");
|
||||
|
||||
while (!stoppingToken.IsCancellationRequested)
|
||||
{
|
||||
@@ -23,7 +24,7 @@ namespace TemplateNETService
|
||||
|
||||
public override async Task StopAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
Log.Debug("Der Service wird gestoppt.");
|
||||
Log.Debug("Service stopped...");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
16
TemplateNETService/Controllers/ServiceController.cs
Normal file
16
TemplateNETService/Controllers/ServiceController.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace TemplateNETService.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api")]
|
||||
public class ServiceController : ControllerBase
|
||||
{
|
||||
[HttpGet]
|
||||
[Route("ping")]
|
||||
public IActionResult GetStatus()
|
||||
{
|
||||
return Ok();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user