The Mvx IoC container

MVVMCross comes with its very own IoC container. It works exactly like our previous example with Autofac, but we are not going to be using modules. Let's begin by registering our sound handler implementation; open our AppDelegate.cs file and create a new private function called setupIoC:

private void SetupIoC() 
{ 
     Mvx.RegisterType<ISoundHandler, SoundHandler>(); 
} 

We must also register our view-models so we can retrieve registered interfaces within our view-model's constructor. Let's add a new folder called IoC inside our AudioPlayer.Portable project. Add a new file called PortableMvxIoCRegistrations.cs and implement the following:

public static class PortableMvxIoCRegistrations { public static void InitIoC() { Mvx.IocConstruct<MainPageViewModel>(); ...

Get Xamarin Blueprints now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.