Skip to content

Commit 8932a8d

Browse files
committed
Fix: Injector destroys instance even if it doesn't manage them.
1 parent d3587f7 commit 8932a8d

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/hex/di/Injector.hx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,15 +250,23 @@ class Injector
250250

251251
public function destroyInstance( instance : Dynamic ) : Void
252252
{
253-
this._managedObjects.remove( instance );
253+
//#if php
254+
if ( this._managedObjects.containsKey( instance ) )
255+
{
256+
this._managedObjects.remove( instance );
257+
instance.__ap();
258+
}
259+
/*#else
254260
try
255261
{
262+
this._managedObjects.remove( instance );
256263
instance.__ap();
257264
}
258265
catch ( e : Dynamic )
259266
{
260267
261268
}
269+
#end*/
262270
}
263271

264272
public function map<T>( type : Class<T>, name : String = '' ) : InjectionMapping<T>

test/hex/di/InjectorTest.hx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,10 @@ class InjectorTest implements IInjectorListener
729729
var target = new Clazz();
730730
Assert.isFalse( target.preDestroyCalled, "target.preDestroyCalled should be false" );
731731
this.injector.destroyInstance( target );
732+
Assert.isFalse( target.preDestroyCalled, "target.preDestroyCalled should be false" );
733+
this.injector.map( Clazz ).toType( Clazz );
734+
target = this.injector.getOrCreateNewInstance( Clazz );
735+
this.injector.destroyInstance( target );
732736
Assert.isTrue( target.preDestroyCalled, "target.preDestroyCalled should be true" );
733737
}
734738

0 commit comments

Comments
 (0)