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...