@@ -52,7 +52,7 @@ public ObjectLifecycleService(
5252 /// Tracks the resolved objects so reference counting works correctly across all tests.
5353 /// Does NOT call IAsyncInitializer (deferred to execution).
5454 /// </summary>
55- public async Task RegisterTestAsync ( TestContext testContext )
55+ public async Task RegisterTestAsync ( TestContext testContext , CancellationToken cancellationToken = default )
5656 {
5757 var objectBag = testContext . StateBag . Items ;
5858 var methodMetadata = testContext . Metadata . TestDetails . MethodMetadata ;
@@ -61,7 +61,7 @@ public async Task RegisterTestAsync(TestContext testContext)
6161
6262 // Resolve property values (creating shared objects) and cache them WITHOUT setting on placeholder instance
6363 // This ensures shared objects are created once and tracked with the correct reference count
64- await PropertyInjector . ResolveAndCachePropertiesAsync ( testClassType , objectBag , methodMetadata , events , testContext ) ;
64+ await PropertyInjector . ResolveAndCachePropertiesAsync ( testClassType , objectBag , methodMetadata , events , testContext , cancellationToken ) ;
6565
6666 // Track the cached objects so they get the correct reference count
6767 _objectTracker . TrackObjects ( testContext ) ;
@@ -75,15 +75,16 @@ public Task RegisterObjectAsync(
7575 object instance ,
7676 ConcurrentDictionary < string , object ? > objectBag ,
7777 MethodMetadata ? methodMetadata ,
78- TestContextEvents events )
78+ TestContextEvents events ,
79+ CancellationToken cancellationToken = default )
7980 {
8081 if ( instance == null )
8182 {
8283 throw new ArgumentNullException ( nameof ( instance ) ) ;
8384 }
8485
8586 // Inject properties during registration
86- return PropertyInjector . InjectPropertiesAsync ( instance , objectBag , methodMetadata , events ) ;
87+ return PropertyInjector . InjectPropertiesAsync ( instance , objectBag , methodMetadata , events , cancellationToken ) ;
8788 }
8889
8990 /// <summary>
@@ -93,7 +94,8 @@ public Task RegisterArgumentsAsync(
9394 object ? [ ] arguments ,
9495 ConcurrentDictionary < string , object ? > objectBag ,
9596 MethodMetadata ? methodMetadata ,
96- TestContextEvents events )
97+ TestContextEvents events ,
98+ CancellationToken cancellationToken = default )
9799 {
98100 if ( arguments == null || arguments . Length == 0 )
99101 {
@@ -106,7 +108,7 @@ public Task RegisterArgumentsAsync(
106108 {
107109 if ( argument != null )
108110 {
109- tasks . Append ( RegisterObjectAsync ( argument , objectBag , methodMetadata , events ) ) ;
111+ tasks . Append ( RegisterObjectAsync ( argument , objectBag , methodMetadata , events , cancellationToken ) ) ;
110112 }
111113 }
112114
@@ -290,7 +292,8 @@ public async ValueTask<T> InjectPropertiesAsync<T>(
290292 T obj ,
291293 ConcurrentDictionary < string , object ? > ? objectBag = null ,
292294 MethodMetadata ? methodMetadata = null ,
293- TestContextEvents ? events = null ) where T : notnull
295+ TestContextEvents ? events = null ,
296+ CancellationToken cancellationToken = default ) where T : notnull
294297 {
295298 if ( obj == null )
296299 {
@@ -301,7 +304,7 @@ public async ValueTask<T> InjectPropertiesAsync<T>(
301304 events ??= new TestContextEvents ( ) ;
302305
303306 // Only inject properties, do not call IAsyncInitializer
304- await PropertyInjector . InjectPropertiesAsync ( obj , objectBag , methodMetadata , events ) ;
307+ await PropertyInjector . InjectPropertiesAsync ( obj , objectBag , methodMetadata , events , cancellationToken ) ;
305308
306309 return obj ;
307310 }
@@ -391,7 +394,7 @@ private async Task InitializeObjectCoreAsync(
391394 // This aligns with ObjectInitializer behavior and provides cleaner stack traces
392395
393396 // Step 1: Inject properties
394- await PropertyInjector . InjectPropertiesAsync ( obj , objectBag , methodMetadata , events ) ;
397+ await PropertyInjector . InjectPropertiesAsync ( obj , objectBag , methodMetadata , events , cancellationToken ) ;
395398
396399 // Step 2: Initialize nested objects depth-first (discovery-only)
397400 await InitializeNestedObjectsForDiscoveryAsync ( obj , cancellationToken ) ;
0 commit comments