Slide 1

Slide 1 text

Staying SOLID with Portable Class Libraries Vagif Abilov @ooobject

Slide 2

Slide 2 text

Why should we care about portable class libraries event when targeting a single platform

Slide 3

Slide 3 text

Case study  Simple.OData.Client  OData client PCL  .NET 4.x  Windows Store  Windows Phone  Silverlight  Mono.Android  Mono.iOS  ODataPad  Cross-platform OData visualization tool

Slide 4

Slide 4 text

ODataPad

Slide 5

Slide 5 text

Here is how it originated Simple.Data API Simple.Data OData adapter OData services

Slide 6

Slide 6 text

As simple as it can get Common API Adapter External service

Slide 7

Slide 7 text

Failed to modify the adapter to run on both .NET4 and Windows Store  Simple.Data.Core references ADO.NET  OData has nothing to do with ADO.NET  Most of OData adapater code deals with either parsing XML documents returned by an OData service or formatting CLR objects as XML documents to send to OData service  These operations should run on any platform

Slide 8

Slide 8 text

Redesigned library Simple.Data API Simple.Data OData adapter Simple.OData.Client PCL OData services

Slide 9

Slide 9 text

But what does this have to do with SOLID principles? Authentication incident

Slide 10

Slide 10 text

User request: implement authentication  First implementation: accept user credentials (user + password), create authentication object using one of supported schemes (Basic, Windows etc.)  Worked like a charm, either to use in client code var odataFeed = new ODataFeed( "http://www.myservice.com/api", "Vagif", "Password123");

Slide 11

Slide 11 text

But bear in mind IT’S NOT PORTABLE !!!

Slide 12

Slide 12 text

Revised implementation for PCL var odataFeed = new ODataFeed( "http://www.myservice.com/api", credentials);  credentials is an instance of a class that implements ICredentials interface  All past and future authentication schemes are supported  PCL conformance enforced use of interface

Slide 13

Slide 13 text

PCL Compliance Analyzer

Slide 14

Slide 14 text

Analyzes any .NET library

Slide 15

Slide 15 text

Reality is more complicated  PCL may not be able to target any subset of platforms  Attempt to choose a set of platforms result in a configuration closely matching the requested set but not necessarily identical to it  While PCL support in Mono is not officially released some extra work required to resolve types that reside in different Mono assemblies than on .NET/Windows

Slide 16

Slide 16 text

Future changes to Simple.OData.Client  Some «cool» features may be removed from PCL for the sake of wide platform support  Lazy, Tuple are not supported on SL4/WP7.5. Should platform set be reduced just because of Lazy[ness]?  C# dynamic is cool, but lack of dynamic support should not discard the whole platform, there should be a fallback to an alternative API  await/async and TPL are cool too but also limit your platforms a) var result = client.FindEntry("Products", x.ProductName == "Chai") b) var result = client.FindEntry("Products?$filter=ProductName eq 'Chai'")

Slide 17

Slide 17 text

PCL to server design-time data: Windows Store

Slide 18

Slide 18 text

... and .NET 4.x

Slide 19

Slide 19 text

... and Windows Phone

Slide 20

Slide 20 text

Summary: bringing PCLs to your projects  Consider making your next business logic module a PCL  Have an overview of portable CLR subset  When selecting external components strive to choose those that have PCLs  Strive to use portable types and values converters (BitmapImage vs. base64 string)  When publishing your PCLs support profiles preferred by your target developer group  Write and test view models first, package them as PCLs, you can go a long way without a single line of UI code

Slide 21

Slide 21 text

Thank you!  [email protected]  @ooobject  GitHub: object  BitBucket: object  Blog: http://bloggingabout.net/blogs/vagif/  Open source projects:  Simple.Data OData adapter  Simple.OData.Client  MongOData (MongoDB OData provider)