SQLite-net-pcl 与 MvvmCross 的问题

Issue with SQLite-net-pcl with MvvmCross

我正在尝试使用 SQlite-net-pcl 来存储一些数据。 正如我从不同的帖子中读到的那样,我必须在我的主项目上创建一个接口服务,然后在我的 Android 和 iOS 项目上实现该服务。 当我尝试在 Android 或 iOS 项目上实现接口时出现问题:

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?)

但是当我尝试添加引用时:

using DemoApplication.Services;

我收到以下错误:

Error CS0234 The type or namespace name 'Services' does not exist in the namespace 'DemoApplication' (are you missing an assembly reference?)

我做错了什么吗?我记得使用另一个框架是在 Android 和 iOS 平台上实现服务的正确形式,但现在在 MvvmCross 中似乎有所不同。

有谁知道正确的形式是怎样做的?

提前致谢。

编辑:

我附上接口定义

namespace DemoApplication.Services
{
    public interface ILocalFileHelperService
    {
        string GetLocalFilePath(string fileName);
    }
}

有时,将新的 .NET Standard class 库添加到您的解决方案时,Visual Studio 的智能感知不会从您的 .NET Standard class 库中获取对代码的更改参考项目。重新启动 Visual Studio 似乎可以解决问题。


关于你的第二个问题

Do you know how I have to register the Interfece or beeing an mvvmcros Project it's not necessary?

有必要。 MvvmCross 在您的 Setup.cs class 内部提供 options 允许您针对核心项目中定义的通用接口注册您的平台特定实现。

  • 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.

例子

protected override void InitializeFirstChance()
{
    Mvx.LazyConstructAndRegisterSingleton<ILocalFileHelperService, LocalFileHelperService >();
}