Implementing the IoC container and modules

Just like our last projects, we are going to set up another IoC container using Autofac. Let's first add the Autofac nuget packages to all projects in the solution. We can then copy the IoC folder from the Stocklist.Portable project in Chapter 5, Building a Stocklist Application. Make sure you include both the IoC.cs and IModule.cs files.

Now let's hop over to the native projects, add the Modules folder in the iOS and Android projects, and implement IOSModule.cs and DroidModule.cs:

public class IOSModule : IModule 
    { 
        #region Public Methods
        public void Register(ContainerBuilder builder)
        {
           builder.RegisterType<SQLiteSetup>().As<ISQLiteSetup>().SingleInstance();
           builder.RegisterType<SQLitePlatformIOS>().As<ISQLitePlatform>().SingleInstance();
        }
        #endregion 
    }

and the DroidModule,

public class DroidModule : IModule
    {
        #region Public Methods
        public void Register(ContainerBuilder builder) 
        {
            builder.RegisterType<SQLiteSetup>().As<ISQLiteSetup>().SingleInstance();
            builder.RegisterType<SQLitePlatformAndroid>().As<ISQLitePlatform>().SingleInstance();
        }
    #endregion 
}

Note

Notice how quick we are piecing things together?

When you have the right direction in building cross-platform applications, the complexity of multiple platform support should not be an issue.

Inside both of the aforementioned modules we are registering the SQLiteSetup and SQLitePlatformIOS/Droid objects so the SQLiteStorage implementation can use these items inside the FileStorage.Portable project.

Before we get back to finishing off the SQLiteStorage implementation, we are going to set up a useful logging approach that can be used in all cross-platform applications.

..................Content has been hidden....................

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