mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge pull request #1184 from ajshort/named-services
BUG: Fixed the injection of named services.
This commit is contained in:
commit
37e10d14f3
@ -692,6 +692,7 @@ class Injector {
|
|||||||
* Register a service with an explicit name
|
* Register a service with an explicit name
|
||||||
*/
|
*/
|
||||||
public function registerNamedService($name, $service) {
|
public function registerNamedService($name, $service) {
|
||||||
|
$this->specs[$name] = array('class' => get_class($service));
|
||||||
$this->serviceCache[$name] = $service;
|
$this->serviceCache[$name] = $service;
|
||||||
$this->inject($service);
|
$this->inject($service);
|
||||||
}
|
}
|
||||||
|
@ -523,6 +523,15 @@ class InjectorTest extends SapphireTest {
|
|||||||
|
|
||||||
$this->assertInstanceOf('OtherTestObject', $item->property->property);
|
$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 {
|
class InjectorTestConfigLocator extends SilverStripeServiceConfigurationLocator implements TestOnly {
|
||||||
|
Loading…
Reference in New Issue
Block a user