mldisibio
Can i use async/await in class constructors?
The static factory method suggested by @Pobiega is the way to go. But there is an alternative. You can fire a Task from the constructor and then get the result using
await
later in a non-constructor method.
6 replies
Passing Lambda as a method parameter: Some issues
I'm curious though. Is this going against an RDBMS table, or is it Linq-to-Entity, or is it against a document database? If ClassB is a nested property of ClassA, does your query presume a join clause?
9 replies
Passing Lambda as a method parameter: Some issues
I'm familiar enough with what you are doing to re-iterate that Albahari should be a gold-standard reference. But I gave up on this approach about ten years ago and went with explicit SQL and some extensions that wrapped simple Ado.Net operations with a fluent api. I won't be able to help you much with the Visitor pattern and expression tree builder needed here. 😕
9 replies
Passing Lambda as a method parameter: Some issues
Ah, so you are really building the
IQueryable
! I got frustrated in my attempts years ago, but have a look at Joe Albahari's approach here: https://www.albahari.com/nutshell/linqkit.aspx9 replies
API structure
That's really an infrastructure question. What is your actual client base and how robust is your server, is it in the cloud and can it scale, etc. In today's world, 100 requests is child's play, and if the data is already cached in Redis, there is no compute, just network traffic. If it were really an issue, you could push the client requests onto a queue and respond to them one at time, but I would load test first and see if that is really a problem.
There are reverse proxies and load balancers out there to solve that problem, so look into those before reinventing that wheel.
Also, if you are considering a push architecture like SignalR, then heck, the client doesn't even need to send a request...just push the updated data to each client.
15 replies
API structure
Couple of thoughts:
1. the backend that transforms the data and stored it in redis can do the compute to determine if the data changed. If it has changed, you can create a very light pub/sub interaction between Redis and your client and push a notification to your client that the data for a particular station has changed. You could abstract this pattern and do it with Signal R or some other push framework.
2. If you are using http calls, look into
ETag
variations that can be communicated via headers in the http messages, both request and response. Essentially eTags communicate if data has changed and if you treat your station data like a file or binary blob, you could send only the parts that have changed
3. Your idea of a second api that just tells you if the station data has changed is pretty simple and would work as well15 replies
docker-angular-dotnet app
If you run the api in a second container, as @TeBeCo suggests, you can use a docker-compose file to bring them both up and either create an explicit network or let docker-compose do its magic and your api address will be the same name as the service under which the api is defined in the yaml file.
29 replies
docker-angular-dotnet app
localhost
has a different meaning for the containerized angular app. It will look for the api inside the same container. It has no idea you are referring to the host running the container.
To achieve what you want, docker has a few special variables, such as host.docker.internal
and gateway.docker.internal
. For docker run
you would use the --add-host=host.docker.internal:my-api
switch and then point your angular app at my-api
instead of localhost
. Alternatively you could hard code your local pc IP address, but it probably is dynamic, and you probably would need to configure the DNS resolver for the container to use.
For more info simply google those keywords.29 replies
Read process RAM usage in real time from docker container using c#
The
System.Diagnostics
functions work well from inside docker containers (they were a little shaky back in the dotnet 2.0 days). I have this polling memory usage every two seconds if enabled by an environment variable and logging only when the memory usage increases. I've compared the output with docker stats
and it mirrors the container memory usage output.2 replies
I am trying to debug a webapi project in a docker container, but breakpoints are not being hit
is the container running on the same machine you are debugging from?
I ask because debugging a container is ridiculously complex to get working and debugging a remote container is exponentially worse.
I got debugging to work on a container running in my WSL2 using VS Code and the remote container extensions. Had to use
System.Diagnostics.Debugger.Break();
to get the first breakpoint, then I could use the IDE to add additional breakpoints on the fly.2 replies
Method for printing collections.
I don't recommend complex approaches with funky dependencies, but in your case, if you are looking to display any variety of collection or object graphs, this is well-known feature of LinqPad
Dump()
that is so popular people ask to incorporate it into Visual Studio or c# projects. Since LinqPad comes with a standalone executable, it's an option, albeit somewhat convoluted: https://stackoverflow.com/a/73541726/45835418 replies