My answer to this is to use dependency injection where possible.
This N+1 covers two ways of doing that:
- firstly by defining interfaces in the core project, and manually registering implementations in each UI project
- 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:
- a presentation on plugins at https://speakerdeck.com/cirrious/plugins-in-mvvmcross
- a full explanation of MvvmCross IoC on http://stackoverflow.com/a/16980207/373321
- the 'fractal' example which shows a real example of injecting a 'screen size' service at https://github.com/slodge/MvvmCross-Tutorials/tree/master/FractalGen
- the 'good vibrations' sample for plugins at https://github.com/slodge/MvvmCross-Tutorials/tree/master/GoodVibrations
For more on N+1, see: