A C# core in a modern project
The other groups of this site teach C# on its own. This one puts a C#
program where a modern project often puts it: in the middle, as a
library of business rules, with a layer in front that speaks HTTP or a
line protocol. The core is a validator and a pricing function over one
line of text, and it uses nothing outside the base class library: no
package, no network, no database.
The layer in front is Python 3.14.10, which is in this container, and it
is a real layer: a service that runs the built C# program for every
request, a client of a long-running C# process on standard input, and a
client of an ASP.NET Core minimal API. All three were started here and
called with real requests, and the timing page measures the cost of each
way: 85.3 milliseconds per call through a new process,
0.047 through the daemon, and 2.27 through the API, as the
medians of five runs of twenty calls. The fourth way, a native library
called through ctypes, was measured on the host with the toolchain
installed: 3.50 microseconds per call.
Two pages are honest about their limits. The NativeAOT shared library
needs a linker this image does not have: the page shows the real error of
the publish in the container, the toolchain the host needed, and the
native call the host then ran. The Dockerfile page is written and not
built here, because the image has no Docker daemon inside it; a build of
its first version on the host found three defects, and the page shows
the fixed file and what was wrong.
Read the protocol first, then the core, and then the three ways in the order of the pages: the service, the daemon and the API. The timing page needs all three, and the two test pages close the loop.
Questions
A new set of questions in a new order every time. Choose one answer for each, then check.
-
What is the core of this project?
Answer
A validator and a pricing function over one line of text, base class library only
The core has no package and no network and is called from three places.
-
Which three ways call the core?
Answer
A new process per request, a long-running process on stdin and stdout, and a minimal API
The timing page measures those three.
-
Which way was the fastest per call?
Answer
The long-running process, at about 0.02 milliseconds
The daemon median was 0.023 ms against 88.566 and 1.798.
-
Why is a new process per call slow?
Answer
Every call pays the runtime start of a new dotnet process
The startup page of the C# vs Java group measured about 70 ms for a hello program.
-
Which page is marked "Pending run"?
Answer
NativeAOT and ctypes
The linker the publish needs is not in this image.
-
Which Python version ran the layer here?
Answer
3.14.10
The note of every page names it.
-
What does the Python service do for a request?
Answer
It runs the built C# program through subprocess and returns its line
The service page shows the subprocess call and the answers.
-
Why is the Dockerfile not built here?
Answer
There is no Docker daemon inside the container
The page says so and shows the file.
-
Which layer is tested with unittest?
Answer
The Python layer, both the price function and the HTTP handler
The page runs five tests, two of them against a server on port 0.
-
What does the C# test driver return when every case passes?
Answer
0
The measured run of eight cases ended with status 0.
The C# code on these pages was built with the .NET SDK 10.0.303 and the Python code was run with Python 3.14.10, on Alpine Linux 3.24.3 (x86_64, four processors) in a Docker container.