Skip to content

Commit

Permalink
Merge pull request #51 from DoclerLabs/develop
Browse files Browse the repository at this point in the history
API changed for runtime dependencies
  • Loading branch information
FrancisBourre authored Sep 23, 2016
2 parents 0ed987a + 7ab0c66 commit 30cbfa7
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
6 changes: 4 additions & 2 deletions src/hex/module/dependency/IRuntimeDependencies.hx
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package hex.module.dependency;

import hex.di.mapping.Mapping;

/**
* @author Francis Bourre
*/
interface IRuntimeDependencies
{
function hasMappedDependencies() : Bool;
function addMappedDependencies( serviceDependencies : Array<Class<Dynamic>> ) : Void;
function getMappedDependencies() : Array<Class<Dynamic>>;
function addMappedDependencies( serviceDependencies : Array<Mapping> ) : Void;
function getMappedDependencies() : Array<Mapping>;
}
10 changes: 6 additions & 4 deletions src/hex/module/dependency/RuntimeDependencies.hx
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
package hex.module.dependency;

import hex.di.mapping.Mapping;

/**
* ...
* @author Francis Bourre
*/
class RuntimeDependencies implements IRuntimeDependencies
{
var _mappedDependencies : Array<Class<Dynamic>>;
var _mappedDependencies : Array<Mapping>;

public function new()
{

}

public function addMappedDependencies( serviceDependencies : Array<Class<Dynamic>> ) : Void
public function addMappedDependencies( serviceDependencies : Array<Mapping> ) : Void
{
if ( this._mappedDependencies == null )
{
this._mappedDependencies = new Array<Class<Dynamic>>();
this._mappedDependencies = new Array<Mapping>();
}

this._mappedDependencies = this._mappedDependencies.concat( serviceDependencies );
}

public function getMappedDependencies() : Array<Class<Dynamic>>
public function getMappedDependencies() : Array<Mapping>
{
return this._mappedDependencies;
}
Expand Down
6 changes: 3 additions & 3 deletions src/hex/module/dependency/RuntimeDependencyChecker.hx
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ class RuntimeDependencyChecker
{
if ( dependencies.hasMappedDependencies() )
{
var mappedDependencies : Array<Class<Dynamic>> = dependencies.getMappedDependencies();
var mappedDependencies = dependencies.getMappedDependencies();

for ( dependency in mappedDependencies )
{
if ( !injector.hasMapping( dependency ) )
if ( !injector.hasMapping( dependency.type, dependency.name ) )
{
throw new RuntimeDependencyException( "'" + dependency + "' class dependency is not available during '" + Stringifier.stringify( module ) + "' initialisation." );
throw new RuntimeDependencyException( "'" + dependency + "' dependency is not available during '" + Stringifier.stringify( module ) + "' initialisation." );
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion test/hex/module/ModuleTest.hx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import hex.di.IBasicInjector;
import hex.di.IDependencyInjector;
import hex.di.Injector;
import hex.di.error.MissingMappingException;
import hex.di.mapping.MappingDefinition;
import hex.domain.DomainExpert;
import hex.error.Exception;
import hex.error.IllegalStateException;
Expand Down Expand Up @@ -285,7 +286,7 @@ private class MockModuleForTestingRuntimeDependencies extends Module
override function _getRuntimeDependencies() : IRuntimeDependencies
{
var rd : RuntimeDependencies = new RuntimeDependencies();
rd.addMappedDependencies( [IService]);
rd.addMappedDependencies( [ new MappingDefinition( IService ) ]);
return rd;
}
}
Expand Down

0 comments on commit 30cbfa7

Please sign in to comment.