Adding Dependencies
Inside a singleton, you might need the functionality of another singleton or a built-in module. For that reason, we have developed a way to add dependencies with ease.
➕ Adding a dependency
Since v2.0.0
, dependencies have to be added via an initialization function of the singleton:
local Service = {
lifecycles = { "start" }
}
-- this function is optional, but required for this case
-- and doesn't need to be declared as a lifecycle
-- note: don't yield in here, it halts the whole framework thread
function Service:init(resolver)
self.foo = resolver("@quebec/foo") -- built-in module called "foo"
self.bar = resolver("@services/bar") -- other service called "bar"
-- note: you can also add another controller as a dependency like this:
-- > self.bar = dependency("@controllers/bar")
-- a service called "test" from an instance with the export name "otherInstance"
self.externalTest = resolver("@otherInstance/services/test")
end
function Service:start()
-- You can now call these
print(self.foo:doSomething())
print(self.bar:doSomething())
print(self.externalTest:doSomething())
end
return Service
Last updated