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
BaseServiceextendsBackgroundServicewithStartAsync,StopAsync,TriggerAsynchooks, execution history tracking and trigger subscription management.ServiceManagerdiscovers every registeredIHostedServicethat also implementsIService, exposes start/stop/trigger APIs and pushes status updates toAdminHub.- Trigger implementations (
AtStartTrigger,IntervalTriggeretc.) can be declared inServiceConfigJSON files stored underGlobalConfig.ConfigServicePath. - Config file helpers (
ServiceConfigFile<T>) handle JSON persistence with polymorphic trigger serialization.
Usage
- Derive your service from
BaseService, implement the abstract methods and register it with DI. - Register
IServiceManager(the built-inServiceManager) and callInitializeAsync()during startup. - Create a
{ServiceName}.jsoninsideConfigs/Servicesto toggle activation and triggers without redeploying.
builder.Services.AddSingleton<IServiceManager, ServiceManager>();
builder.Services.AddHostedService<MyCustomService>();
await serviceManager.InitializeAsync();
Integration Points
AdminDashboardMetricServiceand other features listen to service events to provide metrics.- Because the manager raises
OnAppStartandOnAllServicesAvailable, trigger implementations can automatically fire after the host is ready.
Service Events (EventBus)
ServiceManagerpublishesServiceEventinstances viaIEventBusfor lifecycle changes:Service.Started|Stopped|Triggered|TriggerStarted|TriggerFinishedSource = "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.