Project

yadi

0.0
No commit activity in last 3 years
No release in over 3 years
Yet another dependency injection container
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
>= 0
 Project Readme

Yet another dependency injection container.

Why?

  • No need to pre-fill container
  • Classes can be used without a container

Usage

Auto-inject classes

class Foo; end
class Bar; end

class Baz
  # this tells to inject Foo instance as first argument and Bar as bar: option
  include Yadi::Inject('Foo', bar: 'Bar')
  def initialize(foo, bar:)
    @foo, @bar = foo, bar
  end
end

container = Yadi::Container.new
baz = container.make('Baz')

# this gives the same result
baz = Baz.new(Foo.new, bar: Bar.new)

Auto-inject in service container style

class Foo; end
class Bar; end

class Baz
  # this tells to inject values from container
  include Yadi::Inject('service.foo', bar: 'config.bar')
  def initialize(foo, bar:)
    @foo, @bar = foo, bar
  end
end

container = Yadi::Container.new
container['service.foo'] = Foo.new
container['config.bar'] = 'bar'
baz = container.make('Baz')

# this gives the same result
baz = Baz.new(Foo.new, bar: 'bar')

Installation

Add this line to your application's Gemfile:

gem 'yadi'

And then execute:

$ bundle

Or install it yourself as:

$ gem install yadi

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/appelsin/yadi.