The ASP.NET apps I develop/support at work have all been WebForms. So while taking a lovely course by Scott Allen on PluralSight, I decided to skip the IOC crap in my lab. Wrong! In order for the EF DBContext (interface) to be passed into the constructor for my controller, I need magic to occur. StructureMap provides this be giving my app a DBContext object each time the IDepartmentDataSource interface is asked for. See the following controller constructor:
- public DepartmentController(IDepartmentDataSource db)
- {
- _db = db;
- }
What I don’t need is a default parameterless constructor. I could just create a new DBContext myself, but it seems Scott, and others, support this pattern in MVC. I’m not a big fan of magic because it becomes a maintenance nightmare, but alas…