Skip to content

Service Dependency Ordering

The LoL Engine can optionally order service initialization within phases using attributes and a topological sort. This is additive: if no attributes are present, your existing manual order remains unchanged.

Overview

  • Phases are preserved: Core → Feature → Game → Custom. Sorting only happens within a phase.
  • Annotate concrete service classes with dependency hints:
using LoLEngine.Core.ServiceManagement.Dependencies;

[ServiceDependency(typeof(LoLEngine.Core.Events.Interfaces.IEventManager))]
[ServiceDependency(typeof(LoLEngine.Core.ResourceManagement.Interfaces.IResourceService), Optional = true)]
public class MyService : IMyService, ILoLEngineService { ... }
  • Optional = true means "use if present, otherwise ignore".
  • Dependencies that aren't planned in the same phase are ignored (phases already provide high-level ordering).
  • If a cycle is detected, the engine logs a warning and falls back to the manual order for that phase.

When To Use It

  • Use attributes to express clear, local ordering needs without centralizing lists.
  • Start with a few high-value constraints, validate logs, and expand gradually.

Examples in the Engine

These annotations are included to demonstrate the feature and document relationships:

  • AudioService (Feature)
  • Optional dependencies on IEventManager and IResourceService.
  • LocalizationService (Feature)
  • Optional dependencies on IEventManager and IResourceService. Because optional cross-phase dependencies are marked Optional = true, phase ordering takes precedence and missing services do not block initialization.

Independent Services (Not Annotated)

  • Core: EventService, ObjectPoolService, TimeService, ResourceService, CoroutineRunner
  • Feature: CompressionService, AesEncryptionService (uses LoLEngineConfig internally)
  • Feature (annotated): AutoSaveService, QuickSaveService depend on ISaveSystem

Behavior Summary

  • No attributes: original manual order is used.
  • Optional or out-of-phase dependencies: ignored for ordering (no errors).
  • Required missing dependency in phase: logs a warning.
  • Cycles: logs a warning and falls back to manual order.

Troubleshooting

  • If you see a cycle warning, remove or relax one of the constraints (mark Optional) or consolidate phase placement.
  • To trace the plan, enable logging on LogChannel.DependencyChecker.