Erroneous Fatality
✅ Recommended way to handle null results from a repository GET action?
Using exceptions for exceptional cases is fine. I've made 10+ highly concurrent web apps in my career using this approach, haven't had a situation where I needed to optimize that.
35 replies
✅ Recommended way to handle null results from a repository GET action?
Your approach is absolutely fine.
You can do a short-hand version:
Be careful not to create too many specialized exception classes, if you're not actually catching them anywhere. For your usecase, I'd suggest just using an ArgumentException, and having a middleware set up in your API which transforms ArgumentExceptions to 400 HTTP status code responses.
35 replies
❔ Using Microsoft Graph to verify users exist based on IEnumerable<Guid>
Good luck 😄
You've got C# example snippets in the documentation page
(https://learn.microsoft.com/en-us/graph/api/user-list?view=graph-rest-1.0&tabs=csharp#tabpanel_2_csharp)
15 replies
❔ Using Microsoft Graph to verify users exist based on IEnumerable<Guid>
Something like this:
Then use that for the filter parameter, and for the select just use
id
. Then when you get your results back, you can compare the two collections of Ids and figure out which ones are not present in the AD.15 replies
❔ Using Microsoft Graph to verify users exist based on IEnumerable<Guid>
I can't seem to find if the AD has filtering capability of
property in (value1, value2)
. If not, you'd have to transform your list of Ids into a list of string commands and then join them for the filter.15 replies
❔ Using Microsoft Graph to verify users exist based on IEnumerable<Guid>
You could maybe also use the
count
method with $filter. You put your id collection into the $filter, say you want to count only users whose Id is in the $filter, and then in memory you just check if the count of Ids is equal to the result count from the request15 replies
❔ Using Microsoft Graph to verify users exist based on IEnumerable<Guid>
This could help you: https://learn.microsoft.com/en-us/graph/api/user-list?view=graph-rest-1.0&tabs=http
You can call List and use the $filter parameter to filter by ids, and $select parameter to also only return the id properties, to reduce network load.
15 replies
❔ Refactoring strategy pattern to a simpler code
The code as is is quite good.
The only room to reduce boilerplate would be if this implementation is overkill for the purpose.
Do your IOutputSystemStrategy implementations depend on different dependencies (libraries, packages); are they defined in different projects/assemblies?
If not, if they're all in the same project (alongside the factory definition) already, then you don't need the strategy pattern here.
You could just switch on the outputSystem.Type inside your foreach in order to determine where to send the data, and from then on it seems the codeflow is the same for all types.
14 replies
❔ Cancel task on nested exception
A cancellationToken can only be cancelled through its source, so you're right, you'd have to pass it down, and that would be messy.
I always viewed cancellationToken's as inverse exceptions. Exceptions break the execution from the bottom to the top, and cancellation tokens break execution from the top to the bottom.
If I've understood you correctly, you want to stop the execution of RunSmallerTasks and RunBigTask when any of the RunSmallTask breaks? In that case all you need to do is rethrow the exception from the RunSmallTask after you've logged it in telemetry. It will bubble up until the next try catch block or until it stops the whole program.
3 replies