3
votes

I am currently developing a cross-platform application using Xamarin and the great MvvmCross plateform. I would like to know how to design my solution (project architecture) in order for it to contain plateform specific functions (interfaces in the PCL, etc.).

For example, if I want to implement reading a file, what kind of interfaces should I create in the PCL? What other good practices should I follow? Is there another way of doing this?

Thanks

2
For file IO, you can consider my PCL Storage library which already has the interfaces/implementations created for you: pclstorage.codeplex.comDaniel Plaisted

2 Answers

3
votes

The general approach is to define your interfaces in a PCL, which can be used on different platforms and then have platform specific libraries that implement these interfaces.

Inside your different applications for each platform you then wire these interfaces to the correct implementation. Anywhere in your code you can then depend on the interfaces defined inside the PCL. At runtime, the correct platform specific implementation will be passed.

I wrote two blogposts about this which can be usefull (they're about sharing between Win8 and WinPhone but the same concepts apply):

http://www.kenneth-truyers.net/2013/02/24/patterns-for-sharing-code-in-windows-phone-and-windows-8-applications/

http://www.kenneth-truyers.net/2013/03/27/portable-class-libraries-or-source-code-sharing/