问题
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
回答1:
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.EnsureLoadedbefore 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 callEnsureLoaded()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
来源:https://stackoverflow.com/questions/16788164/custom-plugin-in-mvvmcross