Home Arrow Icon Knowledge base Arrow Icon Global Arrow Icon Can I use both Plugin.BLE and MvvmCross.Plugin.BLE in the same project


Can I use both Plugin.BLE and MvvmCross.Plugin.BLE in the same project


Using both Plugin.BLE and MvvmCross.Plugin.BLE in the same project is technically possible, but it might not be the most efficient or recommended approach. Here's why:

1. Purpose and Functionality:
- Plugin.BLE is a cross-platform plugin designed for accessing Bluetooth Low Energy (BLE) functionality. It is suitable for projects that do not require the MVVM architecture or additional features provided by MvvmCross.
- MvvmCross.Plugin.BLE, on the other hand, is specifically designed for projects using the MvvmCross framework. It integrates BLE functionality into the MVVM architecture, allowing for dependency injection and other MvvmCross features.

2. Dependency and Overlap:
- MvvmCross.Plugin.BLE actually references Plugin.BLE internally. This means that if you use MvvmCross.Plugin.BLE, you are indirectly using Plugin.BLE as well. However, using both explicitly could lead to unnecessary complexity and potential conflicts.

3. Usage and Integration:
- If your project is built with MvvmCross, using MvvmCross.Plugin.BLE is more straightforward because it integrates well with the MVVM pattern and allows for dependency injection. You can resolve IBluetoothLE and IAdapter services using MvvmCross's IoC container.
- If you prefer a simpler, non-MVVM approach, Plugin.BLE might be sufficient. However, if you decide to use both, ensure that you manage their instances and functionalities carefully to avoid conflicts.

4. Potential Issues:
- Using both plugins could lead to confusion in managing instances and handling BLE operations. You might end up with multiple adapters or BLE services running, which could cause unexpected behavior or errors.

5. Recommendation:
- If your project uses MvvmCross, stick with MvvmCross.Plugin.BLE for consistency and ease of integration.
- If your project does not use MvvmCross, Plugin.BLE is a simpler choice.
- Avoid using both unless you have a specific requirement that necessitates their combined use, and ensure you handle their integration carefully.

In summary, while it is technically possible to use both plugins in the same project, it is generally not recommended unless you have a compelling reason to do so. The choice should be based on your project's architecture and specific needs.

Citations:
[1] https://learn.microsoft.com/en-us/answers/questions/1518375/which-package-should-i-utilize-for-bluetooth-low-e
[2] https://www.mvvmcross.com/documentation/advanced/customizing-using-App-and-Setup
[3] https://www.nuget.org/packages/MvvmCross.Plugin.BLE/
[4] https://forum.ionicframework.com/t/both-ble-bluetoothle-plugins-seem-not-to-be-loaded-at-all/176776
[5] https://www.nuget.org/packages/MvvmCross.Plugin.BLE/2.2.0-pre5
[6] https://www.npmjs.com/package/cordova-plugin-bluetoothle
[7] https://github.com/mrozema/xamarin-bluetooth-le
[8] https://community.qlik.com/t5/QlikView-App-Dev/Multiple-Versions-of-Similar-Data-for-All-Tables-in-Data-Model/td-p/468796
[9] https://stackoverflow.com/questions/38327176/xamarin-forms-plugins-ble-mvvmcross-plugins-ble