Skip to content

Add async version of TryValidateObjectRecursive method and tests#54

Merged
tgharold merged 4 commits intomasterfrom
20260328-1737
Mar 29, 2026
Merged

Add async version of TryValidateObjectRecursive method and tests#54
tgharold merged 4 commits intomasterfrom
20260328-1737

Conversation

@tgharold
Copy link
Copy Markdown
Owner

@tgharold tgharold commented Mar 28, 2026

  • Added IAsyncRecursiveDataAnnotationValidator interface
  • Updated RecursiveDataAnnotationValidator to implement the async interface
  • Added two new async methods:
    • TryValidateObjectRecursiveAsync(ValidationContext)
    • TryValidateObjectRecursiveAsync(IDictionary<object, object>)
  • Created comprehensive tests for async functionality including:
    • Basic async validation
    • Async collection validation
    • Async recursive structure handling

This maintains all existing functionality while adding async support for use in modern .NET applications.

Claude Code w/ qwen3-coder-30b-a3b-instruct-mlx (4bit). Running the model locally means it took a few hours for Claude to work its way through writing, debugging and testing.

#43

- Added IAsyncRecursiveDataAnnotationValidator interface
- Updated RecursiveDataAnnotationValidator to implement the async interface
- Added two new async methods:
  * TryValidateObjectRecursiveAsync(ValidationContext)
  * TryValidateObjectRecursiveAsync(IDictionary<object, object>)
- Created comprehensive tests for async functionality including:
  * Basic async validation
  * Async collection validation
  * Async recursive structure handling

This maintains all existing functionality while adding async support for use in modern .NET applications.

Claude Code w/ qwen3-coder-30b-a3b-instruct-mlx (4bit)
- Changed from Task.FromResult to Task.Run in async implementations
- This ensures the validation work runs on a thread pool thread rather than blocking the calling thread
- While System.ComponentModel.DataAnnotations is still synchronous, this approach better aligns with proper async patterns in .NET
- Provides better performance characteristics in high-concurrency scenarios (like web applications)
- Maintains exact same functional behavior as before

The underlying validation still uses the synchronous Validator.TryValidateObject methods, but the async API now properly releases calling threads when awaited.
- Added comprehensive deadlock prevention tests to verify proper async behavior
- Tests ensure that async implementations don't create synchronization context deadlocks
- Includes tests for:
  * Basic async execution patterns
  * Collection validation in async context
  * Recursive structure handling in async
  * Error handling with async methods
  * Concurrent async calls

These tests leverage xUnit's built-in synchronization context to expose potential deadlocks by ensuring tests complete properly without hanging.
@tgharold tgharold changed the title [WIP] Add async version of TryValidateObjectRecursive method and tests Add async version of TryValidateObjectRecursive method and tests Mar 29, 2026
@tgharold tgharold merged commit 6d96ac1 into master Mar 29, 2026
1 check passed
@tgharold tgharold deleted the 20260328-1737 branch March 29, 2026 00:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant