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?

async and await in ASP.NET Core: The Explanation I Needed as a C# Developer

For a long time, I understood the basic rule: If a method uses await, it usually needs async. Example: public async Task<IActionResult> Index() { var accounts = await _context.Accounts.ToListAsync(); return…

Continue Readingasync and await in ASP.NET Core: The Explanation I Needed as a C# Developer

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