DependencyService if only in shared project

martinwhitman1 326 Reputation points
2021-03-30T15:51:20.567+00:00

Please forgive if this is a stupid question, but: If I'm only going to use a (data access/REST) class in my shared XF project, is there any point to creating an interface and doing DependencyService.Register<ClassNameThatImplementsInterface>()?

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,291 questions
0 comments No comments
{count} votes

Accepted answer
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 68,016 Reputation points Microsoft Vendor
    2021-03-31T07:24:45.4+00:00

    Hello,​

    Welcome to our Microsoft Q&A platform!

    Do you want to use (data access/REST) class in the Android or iOS project? If so, you can use DependencyService to achieve it, The DependencyService class is a service locator that enables Xamarin.Forms applications to invoke native platform functionality from shared code.

    The DependencyService class is a service locator that enables Xamarin.Forms applications to invoke native platform functionality from shared code..

    If the (data access/REST) class in the shared XF project, based on my research, this answer is No.

    Best Regards,

    Leon Lu


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. martinwhitman1 326 Reputation points
    2021-03-31T14:02:06.587+00:00

    Thanks, that's what I thought. I don't know how I would optimize my own implementation in a platform-specific way, so I think I'll leave my data access in the shared project and not do any dependency servicing.

    0 comments No comments