Skip to content
This repository has been archived by the owner on Apr 1, 2019. It is now read-only.

Commit

Permalink
Add an example for scoped services
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin committed Sep 13, 2013
1 parent 0ff0e82 commit b22c265
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
28 changes: 28 additions & 0 deletions examples/scoped_services.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
require 'dependency_injection/container'
require 'dependency_injection/loaders/yaml'

c = DependencyInjection::Container.new
loader = DependencyInjection::Loaders::Yaml.new(c)
loader.load(File.join(File.dirname(File.expand_path(__FILE__)), 'scoped_services.yml'))

class ContainerScopedService
def initialize
puts 'Container scoped initialization'
end
end

class PrototypeScopedService
def initialize
puts 'Prorotype scoped initialization'
end
end

c.get('my.container.scoped.service')
# => Container scoped initialization
c.get('my.container.scoped.service')
# =>

c.get('my.prototype.scoped.service')
# => Prorotype scoped initialization
c.get('my.prototype.scoped.service')
# => Prorotype scoped initialization
6 changes: 6 additions & 0 deletions examples/scoped_services.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
services:
my.container.scoped.service:
class: 'ContainerScopedService'
my.prototype.scoped.service:
class: 'PrototypeScopedService'
scope: 'prototype'
2 changes: 1 addition & 1 deletion lib/dependency_injection/scope_widening_injection_error.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
class ScopeWideningInjectionError < Error
class ScopeWideningInjectionError < Exception
end

0 comments on commit b22c265

Please sign in to comment.