I'm trying to use SQlite-net-pcl to store some data. As I read from different posts, I have to create an interface service on my main project and then implementing from that service on my Android and iOS projects. The issue happens when I try to implement the interface on the Android or iOS project:
namespace DemoApplication.iOS
{
public class LocalFileHelperService : ILocalFileHelperService
{
}
}
Error CS0246 The type or namespace name 'ILocalFileHelperService' could not be found (are you missing a using directive or an assembly reference?)
But when I try to add the reference:
using DemoApplication.Services;
I get the following error:
Error CS0234 The type or namespace name 'Services' does not exist in the namespace 'DemoApplication' (are you missing an assembly reference?)
Am I doing anything wrong? I remember that using another framework that was the correct form to implement services in Android and iOS platforms, but now in MvvmCross seems that is made different.
Does anyone knows how is the correct form to do it?
Thanks in advance.
EDIT:
I attach the interface definition.
namespace DemoApplication.Services
{
public interface ILocalFileHelperService
{
string GetLocalFilePath(string fileName);
}
}
Sometimes when adding a new .NET Standard class library to your a solution Visual Studio's intellisense will not pick up changes to code in your .NET Standard class library from reference projects. Restarting Visual Studio seem to resolve the issue.
In terms of your second question
Do you know how I have to register the Interfece or beeing an mvvmcros Project it's not necessary?
It is necessary. MvvmCross provides options inside of your Setup.cs
class allowing you to register your platform specific implementation against an common interface defined in your core project.
InitializeFirstChance
InitializeLastChance
For many objects the choice of when to initialize - first or last - doesn’t matter. For others, the key choice is whether the service needs to be available before or after the App is created and initialized.
Example
protected override void InitializeFirstChance()
{
Mvx.LazyConstructAndRegisterSingleton<ILocalFileHelperService, LocalFileHelperService >();
}