Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions haxelib.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
"description": "Dependency injector with very fast injections",
"contributors": ["doclerlabs"],
"releasenote": "SpeedInjector implementation",
"version": "git",
"version": "1.0.0-alpha.7",
"url": "https://github.com/DoclerLabs/hexInject",
"dependencies":
{
"hexannotation": "git:https://github.com/DoclerLabs/hexAnnotation.git"
"hexannotation": "1.0.0-alpha.7"
}
}
}
21 changes: 19 additions & 2 deletions src/hex/di/Injector.hx
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,10 @@ class Injector
{
throw( e );
}
catch ( e : Dynamic )
/*catch ( e : Dynamic )
{
//Do nothing
}
}*/

return instance;
}
Expand All @@ -194,6 +194,23 @@ class Injector
return false;
}
}

public function hasMappingForClassName<T>( className : ClassName, ?name : MappingName ) : Bool
{
var mapping = this._mapping[ className | name ];

if ( mapping != null )
{
return true;
}

if ( this._parentInjector != null )
{
return this._parentInjector.hasMappingForClassName( className, name );
}

return false;
}

public function unmap<T>( type : ClassRef<T>, ?name : MappingName ) : Void
{
Expand Down
15 changes: 15 additions & 0 deletions test/hex/di/InjectorTest.hx
Original file line number Diff line number Diff line change
Expand Up @@ -860,6 +860,12 @@ class InjectorTest implements IInjectorListener
{
Assert.isFalse( this.injector.hasMapping( Clazz ),"" );
}

@Test( "Test 'hasMappingForClassName' returns false when mapping doesn't exist" )
public function testHasMappingForClassNameReturnsFalseWhenMappingDoesntExist() : Void
{
Assert.isFalse( this.injector.hasMappingForClassName( "Int" ),"" );
}

@Test( "Test 'hasDirectMapping' returns false for parent mapping" )
public function testHasDirectMappingReturnsFalseForParentMapping() : Void
Expand All @@ -876,6 +882,15 @@ class InjectorTest implements IInjectorListener
this.injector.map( Clazz ).toType( Clazz );
Assert.isTrue( this.injector.hasMapping( Clazz ), "" );
}

@Test( "Test 'hasMapping' returns true for type local mapping" )
public function hasMappingReturnsTrueForTypeLocalMapping() : Void
{
var i:Int = 7;

this.injector.mapClassNameToValue( "Int", i );
Assert.isTrue( this.injector.hasMappingForClassName( Clazz ), "" );
}

@Test( "Test 'hasMapping' returns true for value local mapping" )
public function hasMappingReturnsTrueForValueLocalMapping() : Void
Expand Down