Skip to content

holsee/scopeh

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Scopeh

'an ioc container in ruby for the craic'

  • resolves dependencies (manages dependency tree)
  • register types against symbols
  • scoping allows object lifetime management, including singleton and per thread scope

USAGE

REGISTRATION

    @container.register :foo, Foo

RESOLUTION

    @container.register :foo, Foo
    foo = @container.resolve(:foo)

IMPLICIT DEPENDENCY RESOLUTION

    class Foo
    end

    class Bar
      attr_reader :foo

      def initialize(foo)
        @foo = foo
      end
    end

    @container.register :foo, Foo
    @container.register :bar, Bar
    bar = @container.resolve(:bar)

SCOPES

SINGLETON
    @container.register :foo, Foo, :singleton
    @container.resolve :foo   #<Foo:0x007fb30ab34e20>
    @container.resolve :foo   #<Foo:0x007fb30ab34e20>
SINGLETON PER THREAD
    @container.register :foo, Foo, :singleton_per_thread

    Thread.start do
      @container.resolve :foo   #<Foo:0x007fb30ab34e20>
      @container.resolve :foo   #<Foo:0x007fb30ab34e20>
    end

    Thread.start do
      @container.resolve :foo    #<Foo:0x007fea5382b9d8>
    end

A WORD OF WARNING

This is an Experimentation of ioc container for ruby, this hasn't been tested in anger, nor have I profiled this for memory leaks.

LICENSE (MIT)

Copyright (C) 2013 Steven Holdsworth

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

'an ioc container in ruby for the craic'

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages