Reputation: 225
I want to be able to load Prism modules (or equivalent (Mvx Plugins?)), while using MvvmCross for everything else. How do I go about that?
Longer verison: I'm looking for a way to combine the goodness of MvvmCross (being Cross-platform, having nice ViewModel navigation), adding some Prism love for my WPF application. I'm specifically looking to support Regions and Module Management.
As I understand, using a custom MvxPresenter, I can accomplish what the Region Management support does for me in Prism (please correct me if I'm wrong). However, I cannot get my head around how to allow for dynamically loading of Modules (other Assemblies) without using the Prism Bootstrapper. The reason I don't want to use that, is because I need Mvx's bootstrapper (the Setup) to do its thing - firing up my cross-platform app.
Thanks in advance! :-)
Upvotes: 1
Views: 594
Reputation: 66882
MvvmCross can't do true dynamic loading on all platforms - as the Xamarin.iOS platform won't permit this (and the Android platform also makes it difficult - e.g. see Dynamicly resolving Assemblies without the file name)
The closest MvvmCross comes to this currently is the plugin framework which uses bootstrap files to determine which modules to load.
This sequence is initiated from https://github.com/MvvmCross/MvvmCross/blob/v3/Cirrious/Cirrious.MvvmCross/Platform/MvxSetup.cs#L132
protected virtual void PerformBootstrapActions()
{
var bootstrapRunner = new MvxBootstrapRunner();
foreach (var assembly in GetBootstrapOwningAssemblies())
{
bootstrapRunner.Run(assembly);
}
}
The MvxBootstrapRunner
called by this method uses reflection to find, create and then call "Run" on any IMvxBootstrapAction
concrete class in the specified assembly list - which by default is just the UI assembly. The code for this is: https://github.com/MvvmCross/MvvmCross/blob/v3/CrossCore/Cirrious.CrossCore/Platform/MvxBootstrapRunner.cs#L17
Currently this MvxBootstrapRunner
is only really used for plugins, and I suspect you could base your modules within this plugin framework if you wanted to.
Alternatively, the design intention for the bootstrap runner was that it could be easily adapted for any startup actions - so you should be able to build your own bootstrap based classes using of a template like:
public class ModuleBootstrapAction<TModule>
: IMvxBootstrapAction
where TModule : IModule, new()
{
public virtual void Run()
{
Mvx.CallbackWhenRegistered<IModuleCatalog>(RunAction);
}
protected virtual void RunAction()
{
var catalog = Mvx.Resolve<IModuleCatalog>();
catalog.Add(new TModule());
}
}
public class Module1BootstrapAction<Module1> {}
public class Module2BootstrapAction<Module2> {}
public class Module3BootstrapAction<Module3> {}
For more on MvvmCross startup, see https://github.com/MvvmCross/MvvmCross/wiki/Customising-using-App-and-Setup
For more on MvvmCross plugins, see https://github.com/MvvmCross/MvvmCross/wiki/MvvmCross-plugins
Upvotes: 2