Resolve vs TryResolve in subspace locations #145
Merged
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.
The current behavior of
ISubspaceLocation.Resolve
is to returnnull
if the subspace does not exists, which causes a lot of inconsistencies in audited application code:!
to hide the warningsLooking at the code, only a handful of instances really need to handle the null case, mostly inside the binding itself, or in some test infrastructure, or database boostraper, most of the rest can simply be changed to a "required" semantic (ie: the method would throw with an appropriate error message).
This PR does the following:
Resolve()
method signature to returnValueTask<TSubspace>
(non nullable), and throw anInvalidOperationException
if the location does not exist (or is invalid in some way)TryResolve()
method with the old behavior (returnsnull
if missing).Resolve(..., bool createIfMissing)
intoResolveOrCreate(...)
.What does it change in existing code?
TryResolve()
.ResolveOrCreate()
.How to resolve a subspace in regular business logic code
Example before:
Example after:
How to detect the case when a subspace is missing
Example before:
Example after:
How to automatically create the subspace if it is missing
note: This is not a good practice! You should probably have some bootstraper code that will initialize everything properly, and let normal business logic fail if something is not right
Example before:
Example after: