The goal of DependencyService
is to facilitate the creation of APP that access platform-specific APIs (Android, IOS, Windows Mobile, etc.).
If the study you are doing does not require this portability, you can directly instantiate the object of the class that implements IDatabaseConnection
without using DependencyService
.
database = (new CLASSE_QUE_IMPLEMENTA_IDatabaseConnection()).ConexaoDatabase();
database.CreateTable<Usuario>();
Now, if you're going to use DependencyService
, you'll need to implement 3 things in your project:
1) Set interface
public interface IDatabaseConnection
{
MinhaClasseConexao ConexaoDatabase();
}
2) Create the class that implements interface
public class DatabaseConnectionImplementacao : IDatabaseConnection
{
// implementar código da classe
}
3) Register the class that implements the interface
;
//registrar a classe usando um atributo do namespace da classe
[assembly: Xamarin.Forms.Dependency (typeof (DatabaseConnectionImplementacao ))]
namespace MeuApp.Android
{
public class DatabaseConnectionImplementacao : IDatabaseConnection
{
// implementar código da classe
}
}
See: Introduction to DependencyService
For the description of your problem, you should have taken the first step but did not implement the other two.