瀏覽代碼

fix(di): correct transient lifecycle to not cache instances

Transient instances were incorrectly being cached like scoped instances.
The switch case fallthrough caused TRANSIENT and default lifecycle
resolutions to check scoped_instances cache before creating. Now
TRANSIENT and default cases always create fresh instances.
Billy Barrow 1 周之前
父節點
當前提交
3cc2615ca9
共有 1 個文件被更改,包括 4 次插入2 次删除
  1. 4 2
      src/Scope.vala

+ 4 - 2
src/Scope.vala

@@ -157,13 +157,15 @@ namespace Inversion {
                     break;
                     
                 case Lifecycle.SCOPED:
-                case Lifecycle.TRANSIENT:
-                default:
                     if (!this.scoped_instances.try_get(registration, out result)) {
                         result = create_with_injection_context(this, requested_type, registration);
                         this.scoped_instances.set(registration, result);
                     }
                     break;
+                case Lifecycle.TRANSIENT:
+                default:
+                    result = create_with_injection_context(this, requested_type, registration);
+                    break;
             }
 
             if(!result.get_type().is_a(requested_type)) {