Xamarin - DependencyService NULL

2

Dear, good morning!

I started to see a tutorial to develop a simple app in Xamarin with SQLite, but I'm having a problem with an object that calls DependencyService, it is always null, and I can not find the solution.

The following is the source code:

Connection class:

IConfigInterface:

Problem:

My config object, is null, how do I fix this? I came to read to add an attribute of [assembly: Depencendy (typeof (xxxxx))]. I do not understand about this, I do not know what I need to pass in typeof, whether to step my current class, or if I pass the DependencyService class.

I await answers.

Att.

Felipe Duarte

    
asked by anonymous 02.05.2016 / 16:44

1 answer

4

If you are using Xamarin Forms, you probably need to implement the IConfig interface on each platform. For example, in the MyDb.Droid project, add the following class:

[assembly: Dependency(typeof(ConfigDroid))]
namespace MeuDb.Droid
{
    public class ConfigDroid : IConfig
    {

        private string DiretorioSQLite
        {
            get
            {
                return Environment.GetFolderPath(Environment.SpecialFolder.Personal);
            }
        }

        private ISQLitePlatform Plataforma
        {
            get
            {
                return new SQLite.Net.Platform.XamarinAndroid.SQLitePlatformAndroid();
            }
        }
    }
}

Then you need to make the same implementation for other platforms you are working on, IOS or Windows Phone.

    
14.10.2016 / 19:21