Common causes of DbContext has been disposed

On several occasions over the last couple of years I've seen the following exception being thrown in web applications that use Entity Framework. Once you know what might cause this issue it becomes quite obvious and easy to fix but for a junior developer or someone who hasn't experienced it…

Auto-mapping MVC ViewModels

I recently came across a blog post on LosTechies detailing how AutoMapper could be used to map from models to ViewModels in MVC controllers utilising custom ActionFilters. I found this to be a fantastic way of keeping the code in our controller actions concise, avoiding 'fat controllers'. In essence it…

Simple Injector MVC and Web API

So you want to have both WebAPI and MVC controllers in the same project. You add in the route configurations and the WebAPI controllers and come to run the project however you get an exception like this.. ExceptionMessage=Type 'MyProject.Web.Controllers.api.ProductController' does not have a default constructor…