NuGet ยท nuget

Redeon.SuperSiteEngineCore.Web.Eltheon.Core.Features.Service

Core Feature for Services for Eltheon Framework

Install

Install-Kommandos

dotnet add package Redeon.SuperSiteEngineCore.Web.Eltheon.Core.Features.Service --version 0.9.1
<PackageReference Include="Redeon.SuperSiteEngineCore.Web.Eltheon.Core.Features.Service" Version="0.9.1" />
paket add Redeon.SuperSiteEngineCore.Web.Eltheon.Core.Features.Service --version 0.9.1
Install-Package Redeon.SuperSiteEngineCore.Web.Eltheon.Core.Features.Service -Version 0.9.1

README

Vorschau

Redeon.SuperSiteEngineCore.Web.Eltheon.Core.Features.Service

Overview

The Service feature is the backbone for recurring or ad-hoc background work in Eltheon. It wraps ASP.NET Core hosted services with additional lifecycle events, configuration files, execution history and SignalR notifications so operational tooling can monitor and control them.

Feature Set

  • BaseService extends BackgroundService with StartAsync, StopAsync, TriggerAsync hooks, execution history tracking and trigger subscription management.
  • ServiceManager discovers every registered IHostedService that also implements IService, exposes start/stop/trigger APIs and pushes status updates to AdminHub.
  • Trigger implementations (AtStartTrigger, IntervalTrigger etc.) can be declared in ServiceConfig JSON files stored under GlobalConfig.ConfigServicePath.
  • Config file helpers (ServiceConfigFile<T>) handle JSON persistence with polymorphic trigger serialization.

Usage

  1. Derive your service from BaseService, implement the abstract methods and register it with DI.
  2. Register IServiceManager (the built-in ServiceManager) and call InitializeAsync() during startup.
  3. Create a {ServiceName}.json inside Configs/Services to toggle activation and triggers without redeploying.
builder.Services.AddSingleton<IServiceManager, ServiceManager>();
builder.Services.AddHostedService<MyCustomService>();
await serviceManager.InitializeAsync();

Integration Points

  • AdminDashboardMetricService and other features listen to service events to provide metrics.
  • Because the manager raises OnAppStart and OnAllServicesAvailable, trigger implementations can automatically fire after the host is ready.

Service Events (EventBus)

  • ServiceManager publishes ServiceEvent instances via IEventBus for lifecycle changes:
    • Service.Started|Stopped|Triggered|TriggerStarted|TriggerFinished
    • Source = "Service", Category = "ServiceLifecycle", EventName = $"Service.{Action}"
  • Subscribe by implementing IEventProvider (see Events feature) and registering via DI. Example:
public sealed class ServiceSignalRProvider : IEventProvider
{
    private readonly IHubContext<AdminHub> _hub;

    public ServiceSignalRProvider(IHubContext<AdminHub> hub) => _hub = hub;

    public Task HandleAsync(IEvent @event, CancellationToken ct = default)
    {
        if (@event is ServiceEvent serviceEvent)
        {
            return _hub.Clients.All.SendAsync("ServiceEvent", serviceEvent, ct);
        }
        return Task.CompletedTask;
    }
}

// DI
services.AddEltheonEvents();
services.TryAddEnumerable(ServiceDescriptor.Singleton<IEventProvider, ServiceSignalRProvider>());

This example is fictional and illustrates how another feature (such as SignalR or notifications) can subscribe to service events. The implementation and registration of the provider belong inside the respective consumer feature, not the service feature. This keeps downstream consumers decoupled from the ServiceManager while still allowing them to react in real time.

Diagnostics

Every service run is written to the ExecutionHistory list exposed by IService. The manager broadcasts each change via SignalR, so enabling logging for Redeon.SuperSiteEngineCore.Web.Eltheon.Core.Features.Service and the SignalR hub provides full visibility when debugging stuck or failing services.