-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Update multitenancy logic and improve Result handling:
#7281
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
Merged
sfmskywalker
merged 7 commits into
release/3.6.0
from
bug/tenancy-backward-compatibilty
Feb 11, 2026
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
1e2445b
Update multitenancy logic and improve `Result` handling:
sfmskywalker 0c5f84f
Update src/modules/Elsa.Workflows.Runtime/Services/DefaultWorkflowDef…
sfmskywalker a1d3f03
Add exception handling when accessing `Value` on failed results; intr…
sfmskywalker bc42d48
Merge remote-tracking branch 'origin/bug/tenancy-backward-compatibilt…
sfmskywalker fdda5b1
Add `ThrowIfFailure` method to handle exceptions in `Result` model an…
sfmskywalker ff164ac
Normalize tenant ID handling by using `NormalizeTenantId()` in `Defau…
sfmskywalker 3cc51e8
Normalize tenant ID usage in unit tests by returning `tenantId.Normal…
sfmskywalker File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| namespace Elsa.Common.Models; | ||
|
|
||
| /// <summary> | ||
| /// A strongly typed monad that runs either the <see cref="OnSuccess"/> or <see cref="OnFailure"/> lambda, depending on whether or not the operation succeeded. | ||
| /// </summary> | ||
| public class Result<T>(bool success, T? value, Exception? exception) | ||
| { | ||
| /// <summary> | ||
| /// True if the conversion succeeded, false otherwise. | ||
| /// </summary> | ||
| public bool IsSuccess { get; } = success; | ||
|
|
||
| /// <summary> | ||
| /// The result value. Throws an exception if accessed when the result is a failure. | ||
| /// </summary> | ||
| public T Value | ||
| { | ||
| get | ||
| { | ||
| if (!IsSuccess) | ||
| throw new InvalidOperationException("Cannot access Value on a failed result. Check IsSuccess first or use ValueOrDefault.", Exception); | ||
| return value!; | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// The result value, or null/default if the result is a failure. Useful when null is a valid success value. | ||
| /// </summary> | ||
| public T? ValueOrDefault => value; | ||
|
|
||
| /// <summary> | ||
| /// Any exception that may have occurred during the operation. | ||
| /// </summary> | ||
| public Exception? Exception { get; } = exception; | ||
|
|
||
| /// <summary> | ||
| /// Runs the provided delegate if the result is successful. | ||
| /// </summary> | ||
| public Result<T> OnSuccess(Action<T> successHandler) | ||
| { | ||
| if (IsSuccess) | ||
| successHandler(Value); | ||
|
|
||
| return this; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Runs the provided async delegate if the result is successful. | ||
| /// </summary> | ||
| public async Task<Result<T>> OnSuccessAsync(Func<T, Task> successHandler) | ||
| { | ||
| if (IsSuccess) | ||
| await successHandler(Value); | ||
|
|
||
| return this; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Runs the provided delegate if the result is unsuccessful. | ||
| /// </summary> | ||
| public Result<T> OnFailure(Action<Exception> failureHandler) | ||
| { | ||
| if (Exception != null) | ||
| failureHandler(Exception); | ||
|
|
||
| return this; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Runs the provided async delegate if the result is unsuccessful. | ||
| /// </summary> | ||
| public async Task<Result<T>> OnFailureAsync(Func<Exception, Task> failureHandler) | ||
| { | ||
| if (Exception != null) | ||
| await failureHandler(Exception); | ||
|
|
||
| return this; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Throws the exception if the result is a failure. | ||
| /// </summary> | ||
| public Result<T> ThrowIfFailure() | ||
| { | ||
| if (!IsSuccess && Exception != null) | ||
| throw Exception; | ||
|
|
||
| return this; | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// A simple monad that runs either the <see cref="Result{T}.OnSuccess"/> or <see cref="Result{T}.OnFailure"/> lambda, depending on whether or not the operation succeeded. | ||
| /// </summary> | ||
| public class Result(bool success, object? value, Exception? exception) : Result<object>(success, value, exception) | ||
| { | ||
| /// <summary> | ||
| /// Creates a successful result with the specified value. | ||
| /// </summary> | ||
| public static Result<T> Success<T>(T value) => new(true, value, null); | ||
|
|
||
| /// <summary> | ||
| /// Creates a failed result with the specified exception. | ||
| /// </summary> | ||
| public static Result<T> Failure<T>(Exception exception) => new(false, default, exception); | ||
| } |
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
This file was deleted.
Oops, something went wrong.
26 changes: 16 additions & 10 deletions
26
src/modules/Elsa.Persistence.EFCore.Common/EntityHandlers/ApplyTenantId.cs
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
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
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
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.