The Luau Dependency Injection container based on constructors.
With pesde:
$ pesde add intervinn/wirebox
$ pesde installSee /examples for more.
local wirebox = require("wirebox")
local collection = wirebox.Collection.new()
local inject = wirebox.createInjector(collection)
local Logger = {}
Logger.__index = Logger
function Logger.new()
return setmetatable({}, Logger)
end
function Logger:log(msg)
print(msg)
end
inject(Logger.new)
:asTransient()
local App = {}
App.__index = App
function App.new(logger)
return setmetatable({
logger = logger
}, App)
end
function App:hello()
self.logger:log("world")
end
inject(App.new)
:with(Logger.new)
:asSingleton()
local provider = collection:BuildProvider()
local app = provider:Get(App.new)
if not app then return end
app:hello()Contributions are heavily welcomed! There are no contributions guide currently. If you have an idea to improve the project, open the issue before working on a PR.
This project is licensed under the MIT license.