Dependency in xamarin forms is not working.

srsivaprasadsrsivaprasad USMember ✭✭
edited September 2016 in Xamarin.Forms

This is my interface

namespace SampleApp.Services
{
    public interface IAddressBook
    {
        string  FindAllContacts();
    }
}

I implemented the interface in droid project like this.

[assembly: Dependency(typeof(SampleApp.Droid.Services.AddressBook))]
namespace SampleApp.Droid.Services
{
    public class AddressBook : IAddressBook
    {
        public string  FindAllContacts()
        {
            return "helo";
        }
    }
}

I call the method in the xamarin.forms like this.

 protected override void OnAppearing()
        {
            base.OnAppearing();
            var obj = DependencyService.Get<IAddressBook>().FindAllContacts();

        }

I am getting an error like this

Object reference not set to an instance of an object

is there any thing i am missing in my code ?

Thanks in advance.

Answers

Sign In or Register to comment.