Dependencies
You already saw in Lifecycle that OwlInit runs sequentially, in dependency order. This page covers how that order is actually computed a topological sort over the Dependencies you declare on each Service or Controller.
Declaring a dependency
local InventoryService = Owl.CreateService({
Name = "InventoryService",
Dependencies = { "DataService" }, -- > // DataService OwlInit runs before InventoryService
})Each string in Dependencies must match another module's Name field exactly. Owl builds a graph from every loaded Service (or Controller the same mechanism applies to both, independently) and its declared dependencies, then walks that graph to decide OwlInit order.
Why topological order, specifically
With more than one dependency, the graph can branch and Owl guarantees every dependency finishes OwlInit before its dependents start, no matter how the graph is shaped:
-- > // DataService: no dependencies, initializes first
local DataService = Owl.CreateService({ Name = "DataService", Dependencies = {} })
-- > // InventoryService depends on DataService
local InventoryService = Owl.CreateService({
Name = "InventoryService",
Dependencies = { "DataService" },
})
-- > // ShopService depends on both
local ShopService = Owl.CreateService({
Name = "ShopService",
Dependencies = { "DataService", "InventoryService" },
})For this graph, Owl always initializes in the order DataService > InventoryService > ShopService, the only order where every dependency is already initialized before anything that needs it runs. Two Services with no dependency relationship to each other (say DataService and an unrelated LeaderboardService) have no guaranteed order relative to each other, only relative to their own declared dependencies.
When it fails
Owl validates the graph before starting anything and throws immediately with an explicit message rather than initializing modules in an unsafe order:
Missing dependency a name in Dependencies doesn't match any loaded Service:
[Owl] Dependency "DataService" required by "InventoryService" was not found.Circular dependency two or more Services depend on each other, directly or through a chain, so no valid order exists:
[Owl] Dependency cycle detected involving: "ServiceA"A dependency cycle almost always means two Services are trying to do each other's job. The usual fix is extracting the shared piece of logic the part both Services actually need into a third Service that neither depends on the other for.
Keeping Dependencies accurate
Dependencies only affects OwlInit ordering, it has no effect on OwlStart, which always runs in parallel regardless (see Lifecycle). That means if InventoryService:OwlInit() calls Owl.GetService("DataService"), "DataService" must be listed in Dependencies, even though the call itself would silently "work" without it most of the time, until a deploy or a load-order change makes it not work and you're debugging a nil reference that only reproduces intermittently.
Where to go next
- Lifecycle - how
OwlInit's sequential order andOwlStart's parallel order fit together. - Services and Controllers - where
Dependenciesis declared, alongside the rest of a module's options.