Ensuring that your plugin is properly loaded in different MvvmCross versions involves a few key steps, which have evolved over time. Here's a detailed guide on how to achieve this across various MvvmCross versions:
MvvmCross Versions Below 6.0
In versions prior to MvvmCross 6.0, plugins were loaded using bootstrap files. You would create a class that inherits from `MvxPluginBootstrapAction` where `T` is your plugin loader. This approach required manually specifying which plugins to load.
csharp
using MvvmCross.Platform.Plugins;
namespace MyNamespace
{
public class MyPluginBootstrap : MvxPluginBootstrapAction
{
}
}
MvvmCross 6.0 and Above
Starting from MvvmCross 6.0, the process became simpler. You no longer need bootstrap files. Instead, you annotate your plugin class with the `[MvxPlugin]` attribute and ensure it inherits from `IMvxPlugin`. The `Load` method in your plugin class is where you register services with the IoC container.
csharp
using MvvmCross.Plugin;
[MvxPlugin]
public class MyPlugin : IMvxPlugin
{
public void Load()
{
// Register services here
Mvx.IoCProvider.RegisterType(() => new MyService());
}
}
Ensuring Plugin Loading
To ensure that your plugin is loaded, especially if it's not explicitly referenced in your project, you can add a reference in the `LinkerPleaseInclude.cs` file:
csharp
public void Include(MyPlugin p)
{
var _ = p;
}
Alternatively, you can manually load the plugin in your `MvxApplication` class:
csharp
public override void LoadPlugins(IMvxPluginManager pluginManager)
{
pluginManager.EnsurePluginLoaded();
}
MvvmCross 9.0 and Above
In MvvmCross 9.0 and later, the framework targets .NET 6.0 exclusively, which means you need to ensure your plugins are compatible with this version. If your plugin uses platform-specific services, ensure they are correctly registered in the `Load` method of your plugin class.
Troubleshooting
If you encounter issues with plugins not loading, check the following:
- Ensure the plugin NuGet package is installed in both your Core and UI projects.
- Verify that the plugin is correctly annotated with `[MvxPlugin]`.
- Use the `IMvxPluginManager` to check which plugins are loaded.
- If using MvvmCross 9.0 or later, ensure compatibility with .NET 6.0.
By following these steps and adapting to the changes in different MvvmCross versions, you can ensure your plugins are properly loaded across various versions of the framework.
Citations:[1] https://www.mvvmcross.com/documentation/plugins/methodbinding
[2] https://www.mvvmcross.com/mvvmcross-9.0.0-release/
[3] https://stackoverflow.com/questions/58331533/how-to-use-an-mvvmcross-plugin-such-as-the-file-plugin
[4] https://www.mvvmcross.com/documentation/plugins/plugins-development
[5] https://www.mvvmcross.com/documentation/plugins/getting-started
[6] https://stackoverflow.com/questions/19014826/mvvmcross-plugin-with-specific-windows-phone-version-specifications?rq=3
[7] https://stackoverflow.com/questions/73128508/how-to-load-plugins-when-updating-to-mvvmcross-6-4-2-from-5-6-2
[8] https://stackoverflow.com/questions/48968243/mvvmcross-plugin-location-fused-5-6-3-not-compatible-with-mvvmcross-droid-suppor
[9] https://www.nuget.org/packages/MvvmCross.Plugin.BLE/
[10] https://www.nuget.org/packages/MvvmCross.Plugin.All/
[11] https://www.mvvmcross.com/mvvmcross-6.0.0-release/