question

MartinWhitman-9960 avatar image
0 Votes"
MartinWhitman-9960 asked MartinWhitman-9960 answered

DependencyService if only in shared project

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>()?

dotnet-xamarinforms
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

LeonLu-MSFT avatar image
1 Vote"
LeonLu-MSFT answered

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.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

MartinWhitman-9960 avatar image
0 Votes"
MartinWhitman-9960 answered

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.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.