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 IOne and ITwo, then the same instance will be returned when resolving both IOne and ITwo.

There is one more part to add to the Application class. We must register the starting point, so add the following line under the RegisterAsLazySingleton function:

RegisterAppStart<MainPageViewModel>(); 
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.135.198.174