Upgrade to Pro — share decks privately, control downloads, hide ads and more …

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)

Nicola Iarocci

March 11, 2016
Tweet

More Decks by Nicola Iarocci

Other Decks in Programming

Transcript

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

    MASTER CODERDOJO OPEN SOURCE TL;DR CODER AT HEART
  2. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. WAIT. THE PORTABLE CLASS, ISN’T THAT REDUNDANT? Yourself & the

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