My first instinct is to use the service resolver to pick the right interface.

For example in the fh-xamarin-sdk push APIs we have a interface IPush which is accessed as follows

```
ServiceFinder.Resolve<IPush>().Register(HandleNotification);
```

ServiceFinder is responsible for determining which implementation is currently linked in the app.  What this means is that when you build xamarin forms for iOS you depend on the iOS implementations in your build configuration and likewise for Android.  This is probably easiest if you have an Android and iOS forms project which bootstrap the whole thing.

Links

IPush Shared code : https://github.com/feedhenry/fh-dotnet-sdk/tree/master/FHSDK/Services/Network
                                  https://github.com/feedhenry/fh-dotnet-sdk/blob/master/FHSDKPortable/Services/Network/Push.cs
Android IPush impl : https://github.com/feedhenry/fh-dotnet-sdk/tree/master/FHXamarinAndroidSDK/Services/Network
Ios push impl          : https://github.com/feedhenry/fh-dotnet-sdk/tree/master/FHXamarinIOSSDK/Services/Network

Example Xamarin apps :https://github.com/feedhenry-templates/pushstarter-xamarin-app

I know these aren't forms apps and that creates a bit of a roadblock to your question, but I think Xamarin is meant to have a bunch of small platform specific projects with a few common ui projects.  There are a few videos where MS talks about developing Xamarin apps that I can hunt down if people are interested.


On Fri, Apr 20, 2018 at 8:59 AM, Vojtech Sazel <vsazel@redhat.com> wrote:
Hi,

we encountered a problem with Aiden and Massimo with the underlying architecture of the multiplatform project in Xamarin. 

We need to have Auth service module accessible from application. But module has some platform specific implementations we need to get.

1) Suppose we have some class Auth implementing IServiceModule. We would have it implemented only using platform-independent. So we can simply do 
MobileCore.Instance.GetInstance<Auth>()
2) But now we need to have some platform specific stuff done in the module, so we create AuthAndroid and AuthIOS extending Auth (which is now abstract) in platform specific projects.

In ordinary pure Android (or iOS respectively) app we can do:
MobileCore.Instance.GetInstance<AuthAndroid>()
3) But we can't do that with Xamarin.Forms app where stuff is in platform independent project.

We can utilize DependencyService in Xamarin.Forms app project or create separate Xamarin.Forms project with Auth, but it seems that code won't be very pretty in this case. 

What can we do to solve this problem?
I think we can debate it further after todays ST1 standup.

--

VOJTĚCH SÁZEL

SENIOR SOFTWARE ENGINEER, RED HAT MOBILE

Red Hat 

Remote Czech Republic

vsazel@redhat.com    IM: vsazel