Hi, I'm using Prism and Xamarin Forms.
I want feature toggle and A/B testing in my application so I have made a Skin service.
This works like this:
I have a folder for the Skin in this folder I have the same structure as all other skins. In Those folders I have xaml-files. ContentPages, ContentViews and so on. In my ViewModel folder, I have the ViewModel all my skins can share. So if I have a CartPage in Skin A I also have a CartPage in Skin B. Skin A and Skin B share the same ViewModel. I can also create a ViewModel for some pages inside a Skin for A/B test of new functions as well if I want to.
I register all my views with Prism.Autofac and I also made an override method to locate my ViewModels when using Autowireup and so on.
The problem I have now is event subscriptions.
When I start Skin A everything is fine. I create for example CartPage inside a tabbed page that subscribes to AddToCartEvent. I also create a ProductPage on my TabbedPage that push AddToCartEvent. All works like a charm.
But as soon I switch to Skin B it creates the ViewModel again (as expected) but now I have two event listeners. That update my cart for both Skins though skin A still exist in mem.
I can add unsubscribe OnDesaperaring, but then I will not have the state on my tabbed page between the active views.
So what I want to do is switch skin and make the old skin instances to be removed as well so I can instead use anonymous event methods. So they wipe out themselves.
But I cant find any solution for this
When Switch skin I want to send the user to my StartPage and the whole application kind of start from zero with just the new skin name set. And no references to all other contentpages, ContentViews in mem
My navigation is like this in pseudocode:
I register all my pages based on skin and name:
A and B are set in the navigation based on active skin
I tried to use ControlTemplate but because of nesting templates, I got Binding problems. And also problems with resource dictionaries of Templates this way.