Notice (2018-05-24): bugzilla.xamarin.com is now in
Please join us on
Visual Studio Developer Community and in the
Mono organizations on
GitHub to continue tracking issues. Bugzilla will remain
available for reference in read-only mode. We will continue to work
on open Bugzilla bugs, copy them to the new locations
as needed for follow-up, and add the new items under Related
Our sincere thanks to everyone who has contributed on this bug
tracker over the years. Thanks also for your understanding as we
make these adjustments and improvements for the future.
Please create a new report on
Developer Community or GitHub with
your current version information, steps to reproduce, and relevant error
messages or log files if you are hitting an issue that looks similar to
this resolved bug and you do not yet see a matching new report.
When using the Messaging center, there's no way to mock it as a dependency unless we write a wrapper layer around it.
In order to follow the SOLID principles and keep Xamarin Forms testable and easy to use:
* Define in an interface the methods we are currently using statically.
* Change the MessagingCenter class to have non static methods, implementing the interface created above.
* Create a singleton instance of the MessagingCenter that anyone can acquire so it keeps the same static behaviour the class had earlier.
If you follow this steps, developers using Xamarin Forms could inject into their classes an IMessagingCenter that could be mocked with Moq or similar tools, and the only change required in their code is replace:
I like your suggestions.
Not sure if this is an option for you, but you could also try checking out the event aggregator in PRISM.
Refering to this? https://msdn.microsoft.com/en-us/library/ff921122.aspx
I like the architecture proposed, but I feel like it will have a greater impact on consumers of the API.
I'd personally wouldn't mind to switch to it, since in the project I'm working on we are barely starting to use the MessagingCenter, but if it were in a later stage and it was more intensely used, I'd be a bit reticent to change it.
New PR: https://github.com/xamarin/Xamarin.Forms/pull/723
Should be fixed in 2.3.5-pre1