Knit
Knit copied to clipboard
.GetService() and .GetController() work on uninitialized services and controllers
When using .GetService()
or .GetController()
the service/controller you're getting doesn't need to exist at the time. This reduces boilerplate.
local service = Knit.CreateService {
Name = "Service";
}
local otherService
function service:KnitStart()
otherService = Knit.GetService("OtherService")
--otherService is ready to use
end
is now
local service = Knit.CreateService {
Name = "Service";
}
local otherService = Knit.GetService("OtherService")
function service:KnitStart()
--otherService is ready to use
end
If you use .GetService()
or .GetController()
and never create the said service, Knit will error while starting:
Service ServiceName is not defined
Controller ControllerName is not defined
Everything should work pretty well, but the types might be a bit wack. So if you plan on merging this then I suggest you take a look at the types and maybe tweak them around a bit.
I think the goal of Knit was to not have weird metatable hacks like AGF did.
I think the goal of Knit was to not have weird metatable hacks like AGF did.
This doesn't utilize any metatables or hacks, just plain old table behavior :)
oh wow, impressive
But you will be need to use controller/service in KnitStart method anyway. Also this solution will make code bigger and more complex. But your solution is great anyway.