-
-
Notifications
You must be signed in to change notification settings - Fork 402
Add api to handle unhandled async rules exceptions #4727
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add api to handle unhandled async rules exceptions #4727
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Source/tests/Csla.test/ValidationRules/DelayedAsynRuleExceptionRoot.cs
Outdated
Show resolved
Hide resolved
Fix typo Co-authored-by: Copilot <[email protected]>
Add missing doc Co-authored-by: Copilot <[email protected]>
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