Permalink
Browse files

BUG: Fixed the injection of named services.

  • Loading branch information...
1 parent 923ad88 commit ff19f3b11a5b616c290f38d1bc293530a581a948 @ajshort ajshort committed Feb 13, 2013
Showing with 10 additions and 0 deletions.
  1. +1 −0 control/injector/Injector.php
  2. +9 −0 tests/injector/InjectorTest.php
View
1 control/injector/Injector.php
@@ -692,6 +692,7 @@ public function registerService($service, $replace=null) {
* Register a service with an explicit name
*/
public function registerNamedService($name, $service) {
+ $this->specs[$name] = array('class' => get_class($service));
$this->serviceCache[$name] = $service;
$this->inject($service);
}
View
9 tests/injector/InjectorTest.php
@@ -523,6 +523,15 @@ public function testConvertServicePropertyOnCreate() {
$this->assertInstanceOf('OtherTestObject', $item->property->property);
}
+
+ public function testNamedServices() {
+ $injector = new Injector();
+ $service = new stdClass();
+
+ $injector->registerNamedService('NamedService', $service);
+ $this->assertEquals($service, $injector->get('NamedService'));
+ }
+
}
class InjectorTestConfigLocator extends SilverStripeServiceConfigurationLocator implements TestOnly {

0 comments on commit ff19f3b

Please sign in to comment.