This repository has been archived by the owner on Apr 1, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add prototype and container scope notion in service
* Add unit tests * Add examples * Update readme
- Loading branch information
Kevin
committed
Sep 16, 2013
1 parent
4e96bac
commit c065b68
Showing
9 changed files
with
140 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
class ScopeWideningInjectionError < Exception | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters