In Chapter 8, Building a WPF .NET Client, we had some help for doing MVVM from a package called Bifrost. This package does not yet support Xamarin, so we are going to borrow some of the concepts from it, although a bit more naïvely implemented. I would recommend taking a look at the source code for Bifrost (http://github.com/dolittle/bifrost), for a fully featured version. For now, however, it will do.
The publish/subscribe mechanism we have is fairly simple to implement. Let's add the interface that represents the functionality we need:
Add an interface called
IMessenger
in the common SignalRChat.Mobile project.Make the interface look as follows:
public interface IMessenger { void Publish<T>(T content); void SubscribeTo<T>(Action<T> receivedCallback); }
We will need an implementation for the interface; add a class called
Messenger
sitting in the same project. Make the class look as follows:public class Messenger : IMessenger { Dictionary<Type,...