12 things I learned from Les Jackson before 2021. Well worth the read
By: Zərifə Rəsullu
Tags: Net Core, Restful Api, Book Review, Tech Book Review, C Sharp Programming

It is about a week I have been reading The Complete ASP.NET Core 3 API Tutorial Hands-On Building, Testing, and Deploying of Les Jackson. Indeed, my aim was to read a hundred pages for a day and I completed the mission almost successfully. I didn’t read the last chapter deliberately, as it isn’t the right time for me to learn this section yet but will cast my mind back to that section in the right time. All in all, I liked the book. What I liked the most about the book was: Its language- which wasn’t very complex to understand. It was explaining almost all the acronyms and new terms and it was telling you if you need to do further search on the topic or not. I was taking the notes but they weren’t arranged. Though, I was going to arrange the notes, then I thought I can also share some here. It looks like a chaos but maybe you should find something useful among them. Let’s start.

REST APIs are “a lightweight way to transfer textual

representations of resources. A “Solution” is really nothing more than a container for one or more related projects; But projects in turn contain the code and other resources to do something useful. You would not put code directly into a Solution. Solution isn’t that much important. It is useful whether you want to “build” all projects within a solution together. Bad request : Your browser sent a request that this server could not understand. Just using an asynchronous controller action does nothing

to improve the time the I/O operation (e.g., database query) takes to complete. It does, however, improve the situation where we may run out of threads (due to blocking) which has positive implications for scaling. There is also some nice usability implications when applied to User Interface design (have you ever used an application that “freezes” when

performing a long-running operation?). Once we have registered our service in the Service Container, whenever we request to make use of a given interface from somewhere else in our app, the DI system will serve up, or “inject,” the concrete class we’ve associated with the interface (aka the “dependency”) in its place. • AddTransient: A service is created each time it is requested from the

Service Container.

• AddScoped: A service is created once per client request

(connection).

• AddSingleton: A service is created once and reused The answer is that we have to give the DI system an entry point where it can perform the “injection of the dependency,” which in this case, it means creating a class constructor for our Controller and providing ICommandAPIRepo as a required input parameter. We call this Constructor Dependency Injection How does our app know which environment it’s in? Quite simply — we tell it! This is where “Environment Variables” come into play, specifically the

ASPNETCORE_ENVIRONMENT variable. You can configure it inside the launchSettings.json

9. So, when an application is launched (via dotnet run)

• launchSettings.json is read (if available).

• environmentVariables settings override system/OS-defined

environment variables.

• The hosting environment is displayed.

10. An operation is idempotent when performing the same operation again gives the same result.

11. When naming your unit test methods, they should follow a construct similar to

<method name>_<expected result>_<condition>

For example:

GetCommandItem_Returns200OK_WhenSuppliedIDIsValid

12. Authentication (The “Who”): Verifies who you are, essentially it

checks your identity is valid.

Authorization (The “What”): Grants the permissions/level of access

that you have.

These are some terms and some points that I took notes of from the book.