简体   繁体   中英

Can the Xamarin Dependency service work if the caller is not using Xamarin.Forms?

Simple question, can the Xamarin.Forms Dependency Service still Get the platform of the caller if the caller is not Xamarin.Forms based or even Xamarin at all?

Now for the setup to the question. I have two app projects, Android and Windows UWP. For various reasons, I don't need iOS and I cannot use Xamarin.Forms for the two. So, I have a native UWP application and Xamarin.Android. These two can still share a lot of code with PCL or better, .NetStandard.

If I am creating libraries, as I am loosely following this post Dependency Service , and the caller of a library like this is Xamarin.Android or UWP (ie not Xamarin Forms) will the Dependency Service in the library still know the platform of the caller? The bottom line is, in the library, I need to know what platform is consuming or calling the library so I can do platform specific code within the library.

As a follow up to this question, a lot of the examples I have seen with Dependency Service use a PCL. Since everybody seems to be moving away from PCL and towards .NetStandard libraries, can this same thing be achieved if the library is .NetStandard?

Thanks!

If you are not using the Xamarin Forms library, then you will not have access to the DependencyService class.

You can use one of the many other DI libraries such as Autofac which is compatible with .NET Standard projects.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM