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

Commit

Permalink
Added InjectionRule#shared(), reverting InjectionRule#local()
Browse files Browse the repository at this point in the history
  • Loading branch information
tschneidereit committed Oct 28, 2011
1 parent 16756de commit 67bb009
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/org/swiftsuspenders/InjectionRule.as
Expand Up @@ -127,6 +127,23 @@ package org.swiftsuspenders
return this;
}

/**
* Enables sharing the mapping with child injectors of the injector it is defined in
* @return The mapping the method is invoked on, allowing for a fluent usage of the
* different options
*/
public function shared() : InjectionRule
{
if (!_local)
{
return this;
}
const provider : DependencyProvider = getProvider();
_local = false;
mapProvider(provider);
return this;
}

public function hasProvider() : Boolean
{
return _creatingInjector.SsInternal::providerMappings[_mappingId] != null;
Expand Down
9 changes: 9 additions & 0 deletions test/org/swiftsuspenders/InjectorTests.as
Expand Up @@ -615,5 +615,14 @@ package org.swiftsuspenders
injector.map(Interface).toType(Clazz).local();
childInjector.getInstance(Interface);
}

[Test]
public function callingSharedTurnsLocalMappingsIntoSharedOnes() : void
{
const childInjector : Injector = injector.createChildInjector();
injector.map(Interface).toType(Clazz).local();
injector.map(Interface).toType(Clazz).shared();
Assert.assertNotNull(childInjector.getInstance(Interface));
}
}
}

0 comments on commit 67bb009

Please sign in to comment.