diff --git a/haxelib.json b/haxelib.json index 4b7b85b..9b03c1a 100644 --- a/haxelib.json +++ b/haxelib.json @@ -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" } -} \ No newline at end of file +} diff --git a/src/hex/di/Injector.hx b/src/hex/di/Injector.hx index 4a2c026..4611d86 100644 --- a/src/hex/di/Injector.hx +++ b/src/hex/di/Injector.hx @@ -164,10 +164,10 @@ class Injector { throw( e ); } - catch ( e : Dynamic ) + /*catch ( e : Dynamic ) { //Do nothing - } + }*/ return instance; } @@ -194,6 +194,23 @@ class Injector return false; } } + + public function hasMappingForClassName( 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( type : ClassRef, ?name : MappingName ) : Void { diff --git a/test/hex/di/InjectorTest.hx b/test/hex/di/InjectorTest.hx index 19ad034..7690bdc 100644 --- a/test/hex/di/InjectorTest.hx +++ b/test/hex/di/InjectorTest.hx @@ -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 @@ -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