Pro Yearly is on sale from $80 to $50! »

Real Life .NET Cross Platform

Real Life .NET Cross Platform

Building a cross-platform, permanent, asynchronous key-value store with today .NET/Xamarin stack (iOS, Android, Windows Desktop)

- Western Europe MVP Community Open Day 2016, Rome
- OpenDomus.net Community Meetup, Rome
- Live recording for Microsoft Channel9 TecHeroes (Italian)

E3550767c858c787c35c280047ff789c?s=128

Nicola Iarocci

March 11, 2016
Tweet

Transcript

  1. CROSS PLATFORM REAL LIFE .NET

  2. NICOLA IAROCCI CO-FOUNDER @C2K LEAD DEV @AMICA MICROSOFT MVP MONGODB

    MASTER CODERDOJO OPEN SOURCE TL;DR CODER AT HEART
  3. REAL LIFE .NET CROSS PLATFORM SHARED PROJECTS ▸Unit of reuse:

    SOURCE CODE ▸Shows up in References node of Solution Explorer ▸Code treated as if it was linked into main project ▸Incorporated into each assembly referencing the project ▸Can have assets such as XAML, JavaScript files, etc. ▸Full access to .NET Framework ▸#ifdef for platform-specific code ▸Since Visual Studio 2013 Update 2
  4. REAL LIFE .NET CROSS PLATFORM PORTABLE CLASSES ▸Unit of reuse:

    ASSEMBLY ▸Shows up References node of Solution Explorer ▸Assembly (.dll) required by referencing projects ▸Lowest common denominator of selected target platforms ▸No assets, just code ▸Platform-specific code requires Inversion of Control (IoC) ▸Since Visual Studio 2010 with Portable Library Tools 2 ▸“Informaly” deprecated in favor of .NET Standard Platform
  5. REAL LIFE .NET CROSS PLATFORM .NET PLATFORM STANDARD

  6. OUR GOALS REAL LIFE .NET

  7. #1 WEB AND DESKTOP APPS ON MODERN .NET PLATFORMS using

    portable classes
  8. #2 IOS, ANDROID, WINPHONE APPS ON XAMARIN using portable classes

  9. #3 SYNC ALL APPS WITH OUR REST API SERVICE powered

    by Python, Eve and Mongo
  10. #4 SUPPORT LEGACY WINFORMS AND ADO.NET ON NET4 Because… XP

    (yeah)
  11. #5 SINGLE CODEBASE for all platforms NET4 included

  12. MEET SIMPLECACHE.NET async, permanent, cross-platform key-value object cache

  13. CROSS PLATFORM KEY-VALUE OBJECT CACHE SIMPLECACHE.NET IN BRIEF ▸runs on

    .NET45+ ▸runs on iOS, Android, WinPhone (Xamarin) ▸runs on .NET4 ▸single codebase ▸open source ▸part of Amica.vNext toolset: auth, REST client, service discovery, storage,
  14. PORTABLE CLASSES OR SHARED PROJECTS? this is the question

  15. THE PCL, IT IS THE WAY, THE TRUTH, AND THE

    LIGHT. FRIENDS DON’T LET FRIENDS USE SHARED PROJECTS. Jason Smith Jan 19, 2016 PCL OR SHARED PROJECT
  16. FOR ME, THE PCL IS JUST TOO CUMBERSOME FOR MOST

    USES. IT IS LIKE USING A CANNON TO KILL A FLY Miguel de Icaza Jan 22, 2016 PCL OR SHARED PROJECT
  17. THEY CAN BE USED TOGETHER ACTUALLY

  18. PCL CAN REFERENCE SHARED PROJECTS just fine

  19. NATIVE PROJECTS CAN ALSO REFERENCE SHARED PROJECTS

  20. CROSS PLATFORM KEY-VALUE OBJECT CACHE SIMPLECACHE.NET CORE PORTABLE CLASS .NET45+

    XAMARIN.FORMS IOS ANDROID WINPHONE PLATFORMS MODERN DESKTOP LEGACY DESKTOP NET4 APPS SHARED PROJECT
  21. CROSS PLATFORM KEY-VALUE OBJECT CACHE SIMPLECACHE.NET CORE PORTABLE CLASS .NET45+

    XAMARIN.FORMS IOS ANDROID WINPHONE PLATFORMS MODERN DESKTOP LEGACY DESKTOP NET4 APPS SHARED PROJECT 99,99% IMPLEMENTATION
  22. SHARED PROJECT CORE

  23. SHARED PROJECT CORE ONE ABASTRACT METHOD

  24. SHARED PROJECT CORE IMPLEMENTATION

  25. CROSS PLATFORM KEY-VALUE OBJECT CACHE SIMPLECACHE.NET CORE PORTABLE CLASS .NET45+

    XAMARIN.FORMS IOS ANDROID WINPHONE PLATFORMS MODERN DESKTOP LEGACY DESKTOP NET4 APPS SHARED PROJECT FULL .NET4 PROJECT
  26. NET4 PLATFORM

  27. NET4 PLATFORM INHERIT FROM CORE CLASS

  28. NET4 PLATFORM JUST OVERRIDE ONE METHOD

  29. NET4 PLATFORM DESKTOP DATABASE PATH

  30. NET4 PLATFORM CLASSIC SQLITE CONNECTION

  31. CROSS PLATFORM KEY-VALUE OBJECT CACHE SIMPLECACHE.NET CORE PORTABLE CLASS .NET45+

    XAMARIN.FORMS IOS ANDROID WINPHONE PLATFORMS MODERN DESKTOP LEGACY DESKTOP NET4 APPS SHARED PROJECT
  32. NET45 PLATFORM

  33. NET45 PLATFORM DEKSTOP DATABASE PATH

  34. NET45 PLATFORM PLATFORM CONNECTION SQLITE-PCL

  35. CROSS PLATFORM KEY-VALUE OBJECT CACHE SIMPLECACHE.NET CORE PORTABLE CLASS .NET45+

    XAMARIN.FORMS IOS ANDROID WINPHONE PLATFORMS MODERN DESKTOP LEGACY DESKTOP NET4 APPS SHARED PROJECT
  36. IOS PLATFORM

  37. IOS PLATFORM IOS DATABASE PATH

  38. IOS PLATFORM PLATFORM CONNECTION SQLITE-PCL

  39. CROSS PLATFORM KEY-VALUE OBJECT CACHE SIMPLECACHE.NET CORE PORTABLE CLASS .NET45+

    XAMARIN.FORMS IOS ANDROID WINPHONE PLATFORMS MODERN DESKTOP LEGACY DESKTOP NET4 APPS SHARED PROJECT NO REDUCED FEATURES SET INDUCTED BY NET4
  40. WAIT. THE PORTABLE CLASS, ISN’T THAT REDUNDANT? Yourself & the

    guy sitting next to you NOW YOU MIGHT BE WONDERING
  41. CROSS PLATFORM KEY-VALUE OBJECT CACHE WHY ADD A PCL LAYER

    TO THE MODERN PLATFORM TOOLSET? ▸SimpleCache is going to be used by a lot of projects: ▸XamarinForms app ▸Discovery Service ▸Authentication ▸REST client ▸Local Storage ▸PCL resolves all SimpleCache references VS adding each and every one to all parent projects ▸Shared Project in each parent project leads to multiple definition warnings in the solution… ▸… which, in turn, leads to explicit casts needed in parent projects ▸“Simple is better than complex” — Zen of Python
  42. CROSS PLATFORM KEY-VALUE OBJECT CACHE SIMPLECACHE.NET CORE PORTABLE CLASS .NET45+

    XAMARIN.FORMS IOS ANDROID WINPHONE PLATFORMS MODERN DESKTOP LEGACY DESKTOP NET4 APPS SHARED PROJECT SQLITE.NET.CORE-PCL
  43. CROSS PLATFORM KEY-VALUE OBJECT CACHE SIMPLECACHE.NET CORE PORTABLE CLASS .NET45+

    XAMARIN.FORMS IOS ANDROID WINPHONE PLATFORMS MODERN DESKTOP LEGACY DESKTOP NET4 APPS SHARED PROJECT CLASSIC SQLITE.NET
  44. SHARED PROJECT CORE BUILD-TIME COMPILATION SYMBOL

  45. REST CLIENT CORE EVE.NET DIGRESSION REFLECTION DISCREPANCIES NET4/NET45

  46. CROSS PLATFORM KEY-VALUE OBJECT CACHE SIMPLECACHE.NET CORE PORTABLE CLASS .NET45+

    XAMARIN.FORMS IOS ANDROID WINPHONE PLATFORMS MODERN DESKTOP LEGACY DESKTOP NET4 APPS SHARED PROJECT INVERSION OF CONTROL
  47. IOS PLATFORM XAMARIN DEPENDENCY SERVICE

  48. XAMARIN FORMS PORTABLE CLASS RETRIEVE PLATFORM IMPLEMENTATION

  49. XAMARIN FORMS PORTABLE CLASS USE IT IN THE MOBILE, SHARED

    CODEBASE
  50. REAL LIFE .NET CROSS PLATFORM OUR WAY OUT OF TROUBLE

    ▸ Shared Projects referenced in both Portable Classes and native .NET libraries. ▸ Use Shared Project directly un legacy .NET projects ▸ Use PCL wrapper in modern .NET and mobile projects ▸ Abstract methods work for us, eventually combined with other IoC techniques like Dependency Service, Bait and Switch, etc. ▸ #ifdef in Shared Project will be honored in Portable Classes (just define the constant in PCL build settings). Use sparingly. ▸ If you don’t need to support legacy frameworks life is easy ▸ This stuff is costantly evolving (.NET Core, Platform Standard, etc.) so stay up to date.
  51. THANKS! Nicola Iarocci @nicolaiarocci / nicolaiarocci.com / me@nicolaiarocci.com SimpleCache http://buff.ly/1WSqUru