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. 2.

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

    MASTER CODERDOJO OPEN SOURCE TL;DR CODER AT HEART
  2. 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
  3. 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
  4. 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,
  5. 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
  6. 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
  7. 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
  8. 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
  9. 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
  10. 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
  11. 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
  12. 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
  13. 40.

    WAIT. THE PORTABLE CLASS, ISN’T THAT REDUNDANT? Yourself & the

    guy sitting next to you NOW YOU MIGHT BE WONDERING
  14. 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
  15. 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
  16. 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
  17. 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
  18. 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.