qqdev
ASP.NET: Elegant controller <-> service interaction
Hey! I am looking for an elegant controller <-> service interaction.
Example (pseudocode):
My issue with this code: The service layer is returning an HTTP status code although the car service shouldn't have to do anything with HTTP stuff.
I thought about adding a dedicated enum which would kinda imitate some of the HTTP status codes (OK, NotFound, Conflict).
Other ideas:
- Throw custom exceptions (don't like this one, exceptions are ugly)
Do you have a more convenient solution for this issue? How do you deal with this kind of stuff?
Thanks in advance!
Related:
- https://stackoverflow.com/questions/76990166/what-should-the-service-layer-return-to-the-controller-when-validating-data-in-s
- https://www.reddit.com/r/dotnet/comments/yyix35/mvc_how_do_you_return_failures_from_services/
15 replies
✅ JSON + ASP.NET attribute usage
Hi! My JSON class looks like this:
It works just fine.
An issue occurs whenever I got code like this:
Binding the model fails now (because the constructor of
Car
is throwing an exception) which results in an HTTP status code 500 (Internal Server Error) instead of my desired 400 (Bad Request).
My current idea (I don't like it): Create a copy of that class without the JSON attributes but with DataAnnotations.
Do you have any other ideas?
Thanks in advance!5 replies
✅ Scoped-based logging: Microsoft interface
Hi! We are planning to make use of scoped-based logging.
We are not quite happy with this approach tho ^
Is there a less repetitive solution for this? We just want to apply the current context to every log message.
Thanks in advance!
156 replies
Async TCP server with many connections
How to create an async TCP server which can handle many connections without creating a dedicated thread for each one?
-
ReceiveAsync(...)
without SocketAsyncEventArgs
is blocking (when being awaited) -> ❌ I guess?
- ReceiveAsync(...)
with SocketAsyncEventArgs
is not blocking -> ✅ I guess?
- BeginReceive(...)
does not block and uses the (async) callback mechanism -> ✅ I guess?
Which one to use?6 replies
❔ This is not a .NET bug, right? (async void)
Hi! Is this by design?
Neither catch nor finally is getting hit. I know that exceptions which are being raised in async void methods are being swallowed but didn't think that those in a try block would get swallowed aswell.
For reference:
https://stackoverflow.com/a/5383408
https://stackoverflow.com/a/16158374
^ Those answers state that the exceptions are getting catched
80 replies