11package hex .di .mapping ;
22
3+ import hex .di .IInjectorContainer ;
4+ import hex .di .Injector ;
35import hex .di .error .MissingMappingException ;
46import hex .di .mock .owner .DependencyOwner ;
57import hex .di .mock .types .Clazz ;
@@ -59,6 +61,21 @@ class MappingDefinitionTest
5961 Assert .methodCallThrows ( MissingMappingException , injector , injector .getInstanceWithClassName , [ " Void->String" ],
6062 " This mapping should have been filtered by the dependency checker" );
6163 }
64+
65+ @Test (" test order of operations" )
66+ public function testInjectIntoHappensAtLast ()
67+ {
68+ var value = new Injectee ();
69+ var mappings : Array <MappingDefinition > = [
70+ { fromType : " hex.di.mapping.MappingDefinitionTest.Injectee" , toValue : value , injectInto : true },
71+ { fromType : " hex.di.mock.types.Interface" , toClass : Clazz2 , asSingleton : true }
72+ ];
73+
74+ var injector = new Injector ();
75+ mappings .addToInjector (injector );
76+ Assert .isNotNull (value .something );
77+ Assert .equals (injector .getInstance (Interface ), value .something );
78+ }
6279}
6380
6481@Dependency ( var _ : Interface , " id" )
@@ -78,4 +95,13 @@ class DependencyOwner implements hex.di.mapping.IDependencyOwner
7895 }
7996
8097 public function getInjector () : IDependencyInjector return this ._injector ;
98+ }
99+
100+ class Injectee implements IInjectorContainer
101+ {
102+ @Inject
103+ @Optional (true )
104+ public var something : Interface ;
105+
106+ public function new () { }
81107}
0 commit comments