MVVMCross setup inside the PCL

Further into the MVVMCross framework, let's begin by building the MvxApplication class.

Note

This is not the same as the application class inside a Xamarin.Forms application.

public class App : MvxApplication 
    { 
        public override void Initialize() 
        { 
            CreatableTypes() 
                .EndingWith("Service") 
                .AsInterfaces() 
                .RegisterAsLazySingleton(); 
        } 
    } 

Pay attention to the CreatableTypes function being called; the function uses reflection to find all classes in the core assembly that are Creatable, meaning they have a public constructor and they are not abstract. Then, following this function, only register the class interfaces with their names ending in Service as lazy singletons.

Note

The lazy singleton ensures that if a class implements ...

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.