0.0
No release in over 3 years
Low commit activity in last 3 years
A fairly simple IOC container based off of silexphp/Pimple
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.17
~> 5.0
~> 10.0
 Project Readme

Leather::Satchel

A simple IOC container based of off silexphp/Pimple

Installation

Add this line to your application's Gemfile:

gem 'leather-satchel'

And then execute:

$ bundle

Or install it yourself as:

$ gem install leather-satchel

Usage

Basic usage

require 'leather/satchel'

container = Leather::Satchel::Container.new

# Insert a value into the container
container['integer'] = 0

# Retrieve a server from the container
value = container['integer']

Defining Services

Passing a lamdba or proc to the container will define a service. Services accept the container as their only argument and return an instance of an object. Instantiation is done only once, further calls to the service return the same instance. As the container is passed to the callable, you can pull in other services and values for instantiating the object.

container['host'] = 'localhost'
container['username'] = 'test_user'
container['password'] = '*********'

container['database'] = proc { |c|
  Database.new(
    c['host'],
    c['username'],
    c['password']
  )
}

database = container['database']

Defining Factory Services

Factory services are services that return a new instance of the object on each call instead of the same instance each time.

container['database'] = container.factory(proc { |c|
  Database.new(
    c['host'],
    c['username'],
    c['password']
  )
})

database = container['database']

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/chrisBirmingham/leather-satchel.