Member-only story
The coding practices we pickup in early learning days are highly influenced by the practices demonstrated by our tutors, be it in a formal class or in an online video or blog tutorial. Depending upon our source of our education, it is very easy to develop inefficient practices early on, that become hard to break or resist when you dive deeper into serious programming.

It’s much better to adopt right practices when starting, so that you don’t fall in trap of building inefficient and/or in-scalable practices, for the sake of quick learning. If you are a C# beginner, this post might help you avoid one or two such pitfalls. If you are already a seasoned programmer, you may question some of your assumptions, or just have fun reading!
I would like to draw your attention to one of the practices demonstrated in almost 100% of the C# tutorials, that is almost 100% wrong.
Database Operations in Controllers
As we learn about Controllers, we realize how powerful they can be. Automatic parsing and validation of request data, performing CRUD operations, and returning the desired response, are some of the typical functions of a Controller, explained in most tutorials. Many tutorials even mention that we should use Dependency Injection (DI) to instantiate DbContext…