Add api to handle unhandled async rules exceptions#4727
Merged
rockfordlhotka merged 7 commits intoOct 4, 2025
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR adds a new API to handle exceptions thrown by asynchronous business rules in CSLA. It introduces the IUnhandledAsyncRuleExceptionHandler interface that allows developers to decide whether to handle specific async rule exceptions and how to handle them.
Key changes:
- New interface
IUnhandledAsyncRuleExceptionHandlerwithCanHandleandHandlemethods - Integration of exception handling into the async rule execution pipeline
- Configuration options to register custom exception handlers via dependency injection
Reviewed Changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
docs/Upgrading to CSLA 10.md |
Documents the new async rule exception handling API and breaking changes |
Source/Csla/Rules/IUnhandledAsyncRuleExceptionHandler.cs |
Defines the new interface for handling async rule exceptions |
Source/Csla/Rules/DontObserveUnhandledAsyncRuleExceptionHandler.cs |
Default implementation that doesn't handle any exceptions |
Source/Csla/Rules/BusinessRules.cs |
Integrates exception handler into async rule execution |
Source/Csla/Core/BusinessBase.cs |
Updates BusinessRules instantiation to include exception handler |
Source/Csla/Configuration/Fluent/CslaOptions.cs |
Adds configuration option for custom exception handlers |
Source/Csla/Configuration/ConfigurationExtensions.cs |
Registers exception handler service in DI container |
Source/tests/Csla.test/ValidationRules/TestUnhandledAsyncRuleExceptionHandler.cs |
Test implementation of the exception handler interface |
Source/tests/Csla.test/ValidationRules/DelayedAsynRuleExceptionRoot.cs |
Test class that creates async rules with exceptions |
Source/tests/Csla.test/ValidationRules/AsyncRuleTests.cs |
Test cases for async rule exception handling |
Source/tests/Csla.test/Csla.Tests.csproj |
Adds project references for code generators |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Fix typo Co-authored-by: Copilot <[email protected]>
Add missing doc Co-authored-by: Copilot <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A new API is added to make it possible to handle exceptions thrown by asynchronous rules.
The new interface to implement is
Csla.Rules.IUnhandledAsyncRuleExceptionHandlerwhich has two methodsbool CanHandle(Exception, IBusinessRuleBase)ValueTask Handle(Exception, IBusinessRuleBase, IRuleContext)CanHandle(...) == trueWith these methods you can now decide whether to handle the exception and how or let the exception be unobserved bubble up and potentially cause a crash.
You can register your implementation in two ways
services.AddScoped<IUnhandledAsyncRuleExceptionHandler, YourImplementation>()services.AddCsla(o => o.UseUnhandledAsyncRuleExceptionHandler<YourImplementation>());. The handler is registered as scoped.The default is still no handling of any exception thrown in an asynchronous rule.
Fixes #4725