Skip to content

A really simple, partitionable, ruby-flavored dependency injector

License

Notifications You must be signed in to change notification settings

quiteliderally/codeine

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Codeine

A simple dependency injector for ruby projects.

Despite how flexible ruby is, and the insistence of some seriously smart people, I frequently run into the need on larger projects to centrally manage my dependencies. I end up building something like Codeine for each one, so I decided to build it one more time and re-use it.

It turns out I agree with basically everything Alexey Petrushin wrote here

Usage

Codeine can operate as either a global or module-local dependency container. Using it globally is the least flexible, but presents the simplest syntax.

require 'codeine'
Codeine.register(:logger){Logger.new}

class Foo
  codeine_inject :logger
  
  def initialize
    logger.log "Initialized..."
  end
end

For library code, and for larger projects, it's probably a better idea to segregate the containers.

require 'codeine'


module ProjectA
  class Foo
    codeine_inject :logger

    def initialize
      logger.log "Initialized..."
    end
  end
end

Codeine.configure(ProjectA) do
  c.register(:logger){Logger.new}
end

foo = ProjectA::Foo.new

The container bound to the ProjectA module will only service injection requests from classes/modules that reside within it

About

A really simple, partitionable, ruby-flavored dependency injector

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages