Project

vcontainer

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

Development

~> 1.0.0
~> 1.5.1
>= 0
~> 2.1.0

Runtime

>= 0
 Project Readme

vcontainer¶ ↑

VContainer is a simple dependency injection framework for Ruby. Dependency injection should be as simple as possible. Whenever you can use the most effective dependecy injection library: “new”.

BasicComponent.new(EmailSender.new)

Otherwise you can always stick to VContainer as a PicoContainer based implementation for Ruby. The acceptance tests show several different ways to use VContainer.

Creating a container and requesting an instance:

class MyComponent end container = VContainer::ContainerDsl.new.register(MyComponent) component = container.provide :my_component

You can use included modules or type based requests:

class MyComponent < Component include BasicInfo end container = VContainer::ContainerDsl.new.register(MyComponent) component = container.provide :component component = container.provide :basic_info Dependecy injection plays nicely:

class Dao end class Clients def initialize(dao) @dao = dao end def all @dao.find(:all) end end container = VContainer::ContainerDsl.new.register(Dao, Clients) clients = container.provide :clients

You can compose containers in order to create different layers of control:

base = VContainer::ContainerDsl.new.register(dao) container = VContainer::ContainerDsl.new(base).register(Clients) clients = container.provide :clients

There is also a singleton provider, that instantiates a type only once.

base = VContainer::ContainerDsl.new base.use VContainer::SingletonProvider.new(Dao) base.provide(:dao)==base.provide(:dao)

As with any decent container, you can register your own “Adapter/Provider”:

base = VContainer::ContainerDsl.new base.use YourAdapterProviderWhatever.new base.provide(:dao) # will invoke your adapter Just check the SimpleProvider, ParentProvider and SingletonProvider examples to roll out your own provider.

Team ==¶ ↑

VContainer was created by Guilherme Silveira and has been developed together with Eric Torti.

Contributing to vcontainer¶ ↑

  • Check out the latest master to make sure the feature hasn’t been implemented or the bug hasn’t been fixed yet

  • Check out the issue tracker to make sure someone already hasn’t requested it and/or contributed it

  • Fork the project

  • Start a feature/bugfix branch

  • Commit and push until you are happy with your contribution

  • Make sure to add tests for it. This is important so I don’t break it in a future version unintentionally.

  • Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.

Copyright © 2010 guilherme silveira. See LICENSE.txt for further details.