How can I create an instance of a class used for data management in a Xamarin application?

Viewed 675

Here is the way I am doing it now:

public partial class App : Application
{
    public static DataManager db;

    public App()
    {
        DB.appUpdated = "Feb 1, 2017";
        DB.appVersion = "0.1";
        InitializeComponent();
        MainPage = ..
    }

    public static DataManager DB
    {
        get
        {
            if (db == null)
            {
                db = new DataManager();
            }
            return db;
        }
    }


    protected override void OnStart()
    {
        App.DB.InitData();
    }
}

What I would like to know is are there better ways to start up a singleton instance of a class in a Xamarin application?

1 Answers
Related