我已将MvvmCross.Sqlite插件添加到我的项目中。也是UWP的SQLite扩展。
我注册了工厂界面:
Mvx.RegisterType<IMvxSqliteConnectionFactory, WindowsSqliteConnectionFactory>();
在我的连接器类中解决它:
private readonly IMvxSqliteConnectionFactory connectionFactory;
public SqliteConnectionCreator(IMvxSqliteConnectionFactory connectionFactory)
{
this.connectionFactory = connectionFactory;
CreateDb();
}
/// <summary>
/// Creates the config and establishe the connection to the sqlite database.
/// </summary>
/// <returns>Established SQLiteConnection.</returns>
public SQLiteConnection GetConnection()
{
return connectionFactory.GetConnection(new SqLiteConfig(OneDriveAuthenticationConstants.DB_NAME, false));
}
private void CreateDb()
{
using (var db = connectionFactory.GetConnection(OneDriveAuthenticationConstants.DB_NAME))
{
db.CreateTable<Account>();
db.CreateTable<Payment>();
db.CreateTable<RecurringPayment>();
db.CreateTable<Category>();
}
}
但是,只要我想访问get Connection或当前平台,它就会遇到异常:
Exception thrown: 'System.DllNotFoundException' in SQLite.Net.Platform.WinRT.dll
注入工厂的类型是WindowsSqliteConnectionFactory我认为什么是正确的。 我的项目引用了mvvmplugin和sqlite.net-pcl,sqlite.net.core-pcl,sqlite.net.async-pcl。
我是否必须在mvx中注册其他内容?或者,如何使用特定于平台的Factory(WindowsSqliteConnectionFactory)没有平台?