Skip to content

intervinn/wirebox

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Wirebox

Pesde

The Luau Dependency Injection container based on constructors.

Install

With pesde:

$ pesde add intervinn/wirebox
$ pesde install

Usage

See /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()

Contributing

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.

License

This project is licensed under the MIT license.

About

Constructor-based Dependency Injection for Luau

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages