我正在尝试使用 SQlite-net-pcl 来存储一些数据。
当我阅读不同的帖子时,我必须在我的主项目上创建一个接口(interface)服务,然后在我的 Android 和 iOS 项目上从该服务实现。
当我尝试在 Android 或 iOS 项目上实现接口(interface)时会出现问题:
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 中似乎有所不同。
有谁知道正确的形式是如何做到的?
提前致谢。
编辑:
我附上接口(interface)定义。
namespace DemoApplication.Services
{
public interface ILocalFileHelperService
{
string GetLocalFilePath(string fileName);
}
}
最佳答案
有时,将新的 .NET Standard 类库添加到您的解决方案时,Visual Studio 的智能感知不会从引用项目中获取对 .NET Standard 类库中代码的更改。重新启动 Visual Studio 似乎可以解决问题。
关于你的第二个问题
Do you know how I have to register the Interfece or beeing an mvvmcros Project it's not necessary?
有必要。 MvvmCross 提供 options在你的
Setup.cs
允许您针对核心项目中定义的通用接口(interface)注册平台特定实现的类。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 >();
}
关于sqlite - 带有 MvvmCross 的 SQLite-net-pcl 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49718385/