Tuesday, June 25, 2013

N=31 - Injection of Platform Specific Services - N+1 Days of MvvmCross

One of the common questions I get asked is how to consume non-portable functionality into portable class library functionality.


My answer to this is to use dependency injection where possible.


This N+1 covers two ways of doing that:

  1. firstly by defining interfaces in the core project, and manually registering implementations in each UI project
  2. secondly by using testable, reusable plugins

In my 'real-world' projects I generally:

  • start with the first approach - it's quick and very easy to do
  • migrate to plugins where I find I have functionality I need to test, or if I think that I might want to reuse that functionality across projects
  • sometimes, rarely, I do also switch back to non-portable code (to file-linking) for cases where the native API which needs consuming is too large to wrap with an interface - but I try to avoid this wherever possible.


The video for today is at:




At one point, you see that I have an assembly version mismatch - sorry about this - it's due to me talking from a development rather than production setup, and it was easily solved using the nuget `Update-Package` command to update all my projects to the same MvvmCross NuGet version.


The code is at: https://github.com/slodge/NPlus1DaysOfMvvmCross/tree/master/N-31-Injection


For more info on this, please also see:


For more on N+1, see:

2 comments:

  1. Excellent video, could plugins be used to make a bridge to use asmx/soap webservices I PCL?

    ReplyDelete