1

I have created a Xamarin solution in Visual Studio 2013 with the following structure:

SOLUTION
    CORE / PCL
    Android
    iOS
    WindowsPhone

Theoretically, the platform-specific projects will only contain GUI code (XAML for WP, axml for Android, and whatever iOS uses - I as yet know nothing about the Cupertinian's way of doing things); all the logic (business and data code, &c) will reside in the Core/PCL folder, with each of the platform projects referencing that.

However, it seems that there is sort of a middle ground: code that is not GUI but also cannot be shared, such as printing code and file I/O, and these are probably just the nostrils of the bathing hippo.

IOW, the CORE / PCL folder is shared, but the code apparently still needs to be branched off within that, based on which platform/device is calling it. To put it in real estate or sociological terms, the Core/PCL area is a multiplex with separate private quarters, not a common area where lions lie down with lambs, diversity is celebrated, etc.

The promised communal bliss thus becomes an "every man for himself" type of compound, with armed guards restricting access to the star-bellied sneeches' area, etc.

What is the common way to handle this shared-on-the-surface-but-not-really scenario? Is Dependency Injection the answer, or...???

UPDATE

In fact, based on what I see here, it may be that separate-code-for-each-scenario isn't even possible when using PCL; it says there, "Because the same Portable Class Library is shared between multiple applications, platform-specific libraries cannot be referenced (eg. Community.CsharpSqlite.WP7)."

Is this really so? If so, the advantage of using PCL is greatly reduced, as it is truly a "lowest common denominator" sort of approach, not unlike the lambasted-by-Xamarin HTML/JavaScript approach used by rivals such as the suicidal PhoneGap ("The ultimate purpose of PhoneGap is to cease to exist.").

But then again, that same page also says this:

"To some extent both disadvantages can be circumvented using the Provider pattern or Dependency Injection to code the actual implementation in the platform projects against an interface or base class that is defined in the Portable Class Library."

So I reckon (I live near Carmel, so I say "reckon" often in [d,r]eference to that most famous of all Carmelites, Clint Eastwood) that the other viable option is File-linking (as they say: "there are two major approaches to code sharing in this manner; file-linking and Portable Class Library (PCL) projects.").

Community
  • 1
  • 1
B. Clay Shannon-B. Crow Raven
  • 8,547
  • 144
  • 472
  • 862

0 Answers0