Skip to content

Commit

Permalink
Fix: Missign mapping exceptions are not thrown. Fix: @optional is set…
Browse files Browse the repository at this point in the history
… to false when it has no value.
  • Loading branch information
FrancisBourre committed Dec 18, 2017
1 parent a6e5b09 commit 0bad1be
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
15 changes: 9 additions & 6 deletions src/hex/di/Injector.hx
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,6 @@ class Injector
return null;
}
}

inline function _getClassDescription( type : Class<Dynamic> )
{
return Reflect.getProperty( type, "__INJECTION" );
}

public function instantiateUnmapped<T>( type : Class<T> ) : T
{
Expand All @@ -149,6 +144,10 @@ class Injector
{
instance = ( cast type ).__ac( this.getInstanceWithClassName );
}
catch ( e : MissingMappingException )
{
throw( e );
}
catch( e : Dynamic )
{
instance = Type.createInstance( type, [] );
Expand All @@ -161,9 +160,13 @@ class Injector
this._applyInjection( instance, type );
}
}
catch ( e : MissingMappingException )
{
throw( e );
}
catch ( e : Dynamic )
{

//Do nothing
}

return instance;
Expand Down
2 changes: 1 addition & 1 deletion test/hex/di/mock/injectees/OptionalClassInjectee.hx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import hex.di.mock.types.MockConstants;
class OptionalClassInjectee implements IInjectorContainer
{
@Inject
@Optional( true )
@Optional
public var property : Interface;

public function new()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class OptionalOneRequiredParameterMethodInjectee implements IInjectorContainer
var m_dependency : Interface;

@Inject
@Optional( true )
@Optional
public function setDependency( ?dependency : Interface ) : Void
{
this.m_dependency = dependency;
Expand Down

0 comments on commit 0bad1be

Please sign in to comment.