I've spent the last 2 years developing WinForms and ASP.Net MVC applications, so it's been a while since I've worked on a .NET Compact Framework project. In case you haven't heard of it, the .NET Compact Framework is a compact sub-set of the .NET framework that can run on devices with limited resources (like phones, blackberries, barcode scanners, etc.). As I began working on the project, I decided up front that I would use the same SOLID principles I use on any other application. I almost hit a roadblock, however, when it came to choosing a Dependency Injection framework.
I began with just a simple roll-your-own dependency resolver. But this solution doesn't work well once you need to inject multiple layers of dependencies and build up your object hierarchies in a more complex fashion. So I did some research into which (if any) DI frameworks support the Compact Framework. It turns out that only one DI framework supports the Compact Framework: Ninject. Typically StructureMap has been my DI container of choice, and recently I've spent some time evaluating the Unity container from Microsoft, but neither of these support the Compact Framework. So I guess I've got a limited number of choices:
- Don't use IoC and dependency injection
- Continue to "roll-my-own" dependency injection tool
- Pray that Jeremy Miller ports StructureMap to the Compact Framework
- Use Ninject
Option 1 is not even a real option. There are too many benefits to be gained from loose coupling and depending on abstractions rather than details. Option 2 seemed feasible at first, until I needed more complicated object hierarchies. I can't hold my breath and wait on something that may never happen, so Option 3 isn't a real option either. So, it looks like I'm going to be heading to Ninja school! I'll let you know how it goes and what I discover along the way.
Tags: agile, ioc, s.o.l.i.d., compact framework, dependency injection