FormsMessageVisualizerService - markjulmar/xamu-infrastructure GitHub Wiki
FormsMessageVisualizerService
The FormsMessageVisualizerService provides a simple wrapper around the Xamarin.Forms Page.DisplayAlert functionality to make it conform to an abstraction - IMessageVisualizerService. This breaks the dependency in a View Model and allows it to be tested properly.
Usage
To use this, you must associate this type with the interface. If you are using the DependencyService, you can do that in your App constructor:
public class App
{
public App()
{
DependencyService.Register<IMessageVisualizerService, FormsMessageVisualizerService>();
}
...
}
Then you can retrieve it in your View Model:
public class MyViewModel
{
IDependencyService ds;
...
void OnError() {
ds.Get<IMessageVisualizerService>()
.Show("Error", "Houston, we have a problem", "OK);
}
}