Erroneous Fatality
Erroneous Fatality
CC#
Created by Sonath on 10/26/2023 in #help
✅ Recommended way to handle null results from a repository GET action?
Alright, peace
35 replies
CC#
Created by Sonath on 10/26/2023 in #help
✅ 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
CC#
Created by Sonath on 10/26/2023 in #help
✅ Recommended way to handle null results from a repository GET action?
Do .FirstOrDefault() instead, no need to check on every query if your dataset is faulty.
35 replies
CC#
Created by Sonath on 10/26/2023 in #help
✅ Recommended way to handle null results from a repository GET action?
It is absolutely fine.
35 replies
CC#
Created by Sonath on 10/26/2023 in #help
✅ Recommended way to handle null results from a repository GET action?
Don't do .SingleOrDefault(), because that will make your queries more complicated. You should trust your Data set, your service code is the one maintaining it.
35 replies
CC#
Created by Sonath on 10/26/2023 in #help
✅ Recommended way to handle null results from a repository GET action?
Also, you might want to use async communication in your repository.
35 replies
CC#
Created by Sonath on 10/26/2023 in #help
✅ Recommended way to handle null results from a repository GET action?
Your approach is absolutely fine. You can do a short-hand version:
Company company = _repository.Company.GetCompany(companyId, trackChanges)
?? throw new ArgumentException("The company was not found.", nameof(companyId));
Company company = _repository.Company.GetCompany(companyId, trackChanges)
?? throw new ArgumentException("The company was not found.", nameof(companyId));
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
CC#
Created by LazyGuard on 10/24/2023 in #help
❔ Refactoring strategy pattern to a simpler code
Just move your logic from the strategy pattern directly to the service code if you don't expect to have different configurations for a single output type.
14 replies
CC#
Created by LazyGuard on 10/24/2023 in #help
❔ Refactoring strategy pattern to a simpler code
Not instead, inside 🙂
14 replies
CC#
Created by alex098304 on 10/25/2023 in #help
❔ Using Microsoft Graph to verify users exist based on IEnumerable<Guid>
Glad to have helped 🙂
15 replies
CC#
Created by alex098304 on 10/25/2023 in #help
❔ 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
CC#
Created by alex098304 on 10/25/2023 in #help
❔ Using Microsoft Graph to verify users exist based on IEnumerable<Guid>
This is all ad-libbed, I've never used AD before now, I was just curious ><
15 replies
CC#
Created by alex098304 on 10/25/2023 in #help
❔ Using Microsoft Graph to verify users exist based on IEnumerable<Guid>
Something like this:
IEnumerable<Guid> ids;
IEnumerable<string> idEquations = ids.Select(id => $"c/id eq '{id}'");
string idsFilter = string.Join(" and ", idEquations);
string filter = $"identities/any(c:{idsFilter})";
IEnumerable<Guid> ids;
IEnumerable<string> idEquations = ids.Select(id => $"c/id eq '{id}'");
string idsFilter = string.Join(" and ", idEquations);
string filter = $"identities/any(c:{idsFilter})";
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
CC#
Created by alex098304 on 10/25/2023 in #help
❔ 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
CC#
Created by alex098304 on 10/25/2023 in #help
❔ 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 request
15 replies
CC#
Created by alex098304 on 10/25/2023 in #help
❔ 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
CC#
Created by LazyGuard on 10/24/2023 in #help
❔ 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
CC#
Created by MechWarrior99 on 10/24/2023 in #help
❔ 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.
public async Task RunSmallerTasksAsync(CancellationToken cancellationToken = default)
{
for(int i = 0; i < k; i++)
try
{
await RunSmallTaskAsync(cancellationToken); // Use the cancellationToken inside your small task, no need to check it here.
}
catch(Exception exception)
{
// Sending telemetry here about the exception.
throw exception;
}
}
public async Task RunSmallerTasksAsync(CancellationToken cancellationToken = default)
{
for(int i = 0; i < k; i++)
try
{
await RunSmallTaskAsync(cancellationToken); // Use the cancellationToken inside your small task, no need to check it here.
}
catch(Exception exception)
{
// Sending telemetry here about the exception.
throw exception;
}
}
3 replies
CC#
Created by Sonath on 10/24/2023 in #help
❔ Referencing new projects with the main project
Yes, CoreProject will have access to Contracts through LoggerService. It's also fine to have both CoreProject and LoggerService reference Contracts, if CoreProject needs to use Contracts code unrelated to the LoggerService usecases.
4 replies
CC#
Created by Tim on 10/23/2023 in #help
✅ Enum and generics
Whenever you use PacketIds.SEND_MESSAGE, you're just using 0
42 replies