Bladeren bron

feat(di): add configure_with method for transient resolution

Add a convenience method that creates a transient scope, registers
a type locally, and resolves it in a single call. This enables
inline configuration and instantiation without prior registration.
Billy Barrow 1 week geleden
bovenliggende
commit
fc35082745
1 gewijzigde bestanden met toevoegingen van 6 en 0 verwijderingen
  1. 6 0
      src/Container.vala

+ 6 - 0
src/Container.vala

@@ -142,6 +142,12 @@ namespace Inversion {
             return register_module_factory_type(typeof(T), new ObjectFactory(typeof(T)));
         }
 
+        public T configure_with<T>() throws Error {
+            var scope = create_transient_scope();
+            var registration = scope.register_local_transient<T>();
+            return (T) scope.resolve_registration(registration);
+        }
+
         public bool is_registered(Type type) {
             return this.registrations.has(type);
         }