Hello Community,
I am new to Xamarin, so please forgive me if the question is a little silly.
I want to build a plugin framework with Xamarin. At the start of the application I want to receive a list of all available plugins. The goal is to give other developers the opportunity to add plugins to the project easily. A modular software structure should be build. Maybe in the future, if there are more platform specific possebilities to pass data in iOS, I am going to devide the whole application into independent standalone apps. In my case a Plugin is not only a little lib for extra functions. The Plugin is a whole software module with his own views and controllers etc.. So I thought about such structure:
PluginManager (Folder)
-PluginManagerForms
--abstract Class Plugin : Xamarin.Forms.Application
--PluginController : Plugin
-PluginManagerForms.Droid
--MainActivity
-PluginManagerForms.iOS
MainModule (Folder)
-MainModuleForms
--MainModuleController : Plugin
--MainModuleView.Xaml
-MainModuleForms.Droid
-MainModule.iOS
Plugin1 (Folder)
-Plugin1Forms
--Plugin1FormsController : Plugin
--Plugin1FormsView
-Plugin1Forms.Droid
-Plugin1Forms.iOS
My idea:
First I thought reflection is what I need. But the problem is, that reflection is not really usable within pcl. So I had to do the reflection stuff in the platform specific project. I was able to get a list of all assemblies and also of all classes which inherit from my abstract plugin class. This all takes place in the android MainActivity of the PluginManager project. In the next step I called dynamically a Xamarin.Forms Application. It was a little tricky. My Plugin class now inherites from Application, so that I can call my Plugin with the LoadApplication() function. Maybe there is a better way to do this, I didn't thought about. The second problem what I am not happy about, is, that using this way I would have to implement it for every platform once.
But nethertheless it is a soloution and it is working up to this point. I dynamically get a list of all Plugins. All the plugin developer has to do, is to let his controller inherit from Plugin and add a reference in the PluginManager project to the new Plugin. We also can organize it, that every other Plugin can request the PluginManager to start another Plugin.
Problem:
I now called the xamarin forms view which displays a list of all plugins. At the end the user should be able to click one of those plugins to open it. In order to organize the whole plugin to plugin stuff I want to implement a central component (PluginManager). I also want build a MVP structure in the project. So the whole communication is only between PluginManager and PluginMainPresenter. What I am not able to ralize, is to call the new Application. In order to use LoadApplication() you have to go back to your platform specific PluginManager project and call the new application from there. This is probably possible by using dependencyService. Maybe anyone knows what LoadApplication() does in the background and how to workaround this problem. I tried to just create the new instance of the new Controller and start the view within the controller by setting the mainpage. It always ends in NullPointerException, because of course the view is not really loaded.
I am open minded for all ideas. Maybe someone has a total different aproach.