Why Put Business Logic in a Service Instead of Stuffing Everything Into an ASP.NET Core Controller?

When building an MVC application, it is very easy to keep adding code to a controller. At first, the action looks harmless: public IActionResult Create() { return View(); } Then…

Continue ReadingWhy Put Business Logic in a Service Instead of Stuffing Everything Into an ASP.NET Core Controller?

GET vs POST in ASP.NET Core MVC: What My Controller Is Actually Doing

I used to see controller code like this: [HttpGet] public IActionResult Create() { return View(); } [HttpPost] public IActionResult Create(CreateAccountViewModel model) { // save something } Both methods were named…

Continue ReadingGET vs POST in ASP.NET Core MVC: What My Controller Is Actually Doing

Why I Use a ViewModel Instead of Sending My EF Core Entity Directly to a View

When I first learned ASP.NET Core MVC, one thing confused me: If I already have an EF Core entity with all my database fields, why would I create another class…

Continue ReadingWhy I Use a ViewModel Instead of Sending My EF Core Entity Directly to a View