Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom plugin in MVVMCross

Tags:

mvvmcross

I'm working on MVVMCross v3 and I want to create my own plugin, I followed this tutorial (which is for the vNext)

http://slodge.blogspot.fr/2012/10/build-new-plugin-for-mvvmcrosss.html

To be compatible for the v3 I changed IMvxServiceConsumer and GetService to Mvx.Resolve.

But on the tutorial there are :

Then, for WinRT, WindowsPhone and MonoTouch clients, you also need to provide a Loader accessor in setup.cs - like:

protected override void AddPluginsLoaders(Cirrious.MvvmCross.Platform.MvxLoaderPluginRegistry loaders)

{
    loaders.AddConventionalPlugin<MyCompany.MvvmCross.Plugins.Mega.WindowsPhone.Plugin>();

    base.AddPluginsLoaders(loaders);
}

How can I do that in v3?

Thanks

like image 581
Podelo Avatar asked Mar 12 '26 07:03

Podelo


1 Answers

If you want to write a new plugin, then :

  • the up-to-date sample is https://github.com/slodge/MvvmCross-Tutorials/tree/master/GoodVibrations
  • there are some notes on this sample in https://speakerdeck.com/cirrious/plugins-in-mvvmcross

For plugin initialisation, the nuget packages now do this via bootstrap files - e.g. see the files added for Location at:

  • (WinRT, WinPhone, Droid) - https://github.com/slodge/NPlus1DaysOfMvvmCross/blob/master/N-08-Location/Location.Droid/Bootstrap/LocationPluginBootstrap.cs
  • (Touch) - https://github.com/slodge/NPlus1DaysOfMvvmCross/blob/master/N-08-Location/Location.Touch/Bootstrap/LocationPluginBootstrap.cs

The bootstrap way is the normal way to do initialisation now.

If you did want to use a non-bootstrap technique then you can do this:

  • In WinRT, WinPhone, and Droid, you don't need to use a loader, but you do need to call MyPlugin.PluginManager.Instance.EnsureLoaded before the plugin can be used.
  • In Touch, you would need to provide a loader during protected override void AddPluginsLoaders(MvxLoaderPluginRegistry loaders) - and you'd then still need to call EnsureLoaded() before the plugin can be used.

For examples of this 'old way' of working, see Setup.cs in the UI projects in https://github.com/slodge/MvvmCross-Tutorials/tree/master/Sample%20-%20TwitterSearch

like image 145
Stuart Avatar answered Mar 14 '26 09:03

Stuart



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!