Portable class libraries (PCLs) allow sharing code across platforms like Windows, Xamarin, and others. A PCL contains code common to selected platforms; it is sliced into platform-specific libraries. PCLs are commonly used for data access, services, view models, utilities, and unit tests. Frameworks like MVVM Light and Json.NET support PCLs. If code can't be shared, platform indirection with a common interface and runtime reflection can achieve similar business logic.
2. ABOUT ME
Agile Developer at Accenture Inc Avanade PDC
Technology Enthusiast
Startup Enthusiast
Mentor to Students
Loves Wine
3. ADVENT OF DIFFERENT PLATFORMS
Windows 10
Xamarin
Desktop / Core .NET
Xbox One
Silverlight
4. THE CHALLENGE
Sharing code between platforms were not that simple
Each platform have a designated Class Library
Shared Project is still limited
5. ORIGIN OF PCL
Microsoft created a Visual Studio extension for VS2012 /
VS2013
6. HOW IT WORKS?
You tick the platforms you like to support. Then
that portable class library will be sliced into
those libraries which are common to them.
8. WHERE DO WE USUALLY USE PCL?
Sharing Data Access and Service
Layer of Apps
Sometimes on ViewModels
Sharing Common Utilities and
Helper Classes
Just One Unit Test for shared
Functionalities
9. SOME LIBRARIES THAT WORKS WITH PCL
MVVM Light
Json.NET
Microsoft HTTP CLIENT Libraries (Microsoft.Net.Http / HttpClient)
10. SPECIAL CASE: WHAT IF YOU CANNOT SHARE CODE
BUT HAVE SAME BUSINESS LOGIC?
Platform Indirection.
You create custom code for that platform, but still extends the
same Interface.
You use reflection to resolve the class at run time.