浏览代码

Adjust on release instances when is object singleton and interfaced

Diogo Aires 8 月之前
父节点
当前提交
cb649c8f78
共有 1 个文件被更改,包括 9 次插入3 次删除
  1. 9 3
      Quick.IOC.pas

+ 9 - 3
Quick.IOC.pas

@@ -467,9 +467,15 @@ begin
     if fDependencyOrder[i] <> nil then
     if fDependencyOrder[i] <> nil then
     begin
     begin
       //free singleton instances not interfaced
       //free singleton instances not interfaced
-      if (fDependencyOrder[i] is TIocRegistrationInstance) and
-          (TIocRegistrationInstance(fDependencyOrder[i]).IsSingleton) then
-            TIocRegistrationInstance(fDependencyOrder[i]).Instance.Free;
+      if (fDependencyOrder[i] is TIocRegistrationInstance) and 
+        (TIocRegistrationInstance(fDependencyOrder[i]).IsSingleton) then
+          TIocRegistrationInstance(fDependencyOrder[i]).Instance.Free
+      else
+      //free singleton instances interfaced
+      if (fDependencyOrder[i] is TIocRegistrationInterface) and 
+        (TIocRegistrationInterface(fDependencyOrder[i]).IsSingleton) and 
+        (Assigned(TIocRegistrationInterface(fDependencyOrder[i]).Instance)) then
+          TIocRegistrationInterface(fDependencyOrder[i]).Instance._Release;
       fDependencyOrder[i].Free;
       fDependencyOrder[i].Free;
     end;
     end;
   end;
   end;