How to use Community SQLite plugin in MVVMCross

2019-07-06 05:10发布

问题:

In my application I was using the old SQLite-plugin. Since MVVMCross 3.0.14 this version is deprecated and the Community.Sqlite plugin is advised.

The Community plugin was added via Nuget.

When trying to use the plugin without a bootstrapper, at runtime I get the error:

Failed to resolve parameter for parameter connectionFactory of type ISQLiteConnectionFactory when creating...

When trying to use the plugin with a bootstrapper, also at runtime, I get the error:

plugin not registered for type Cirrious.MvvmCross.Community.Plugins.Sqlite

How should this plugin be used?

-Edit- This is my bootstrapper code:

using Cirrious.MvvmCross.Community.Plugins.Sqlite;
public class SqlitePluginBootstrap : MvxPluginBootstrapAction<PluginLoader>
{
}

回答1:

Okay, Nuget added a reference to the portable library. I added a reference to the Sqlite.Touch library and then altered my bootstrapper:

using Cirrious.MvvmCross.Community.Plugins.Sqlite;
using Cirrious.MvvmCross.Community.Plugins.Sqlite.Touch;
public class SqlitePluginBootstrap : MvxLoaderPluginBootstrapAction<PluginLoader, Plugin>
{
}

This solved the "plugin not registered"-error for me.



回答2:

Confirmed - I came across the same issue. Nuget downloads the right things, but only adds the one reference, as Jacco points out.

It doesn't add the reference to Cirrious.MvvmCross.Community.Plugins.Sqlite.Touch.dll, and it doesn't put the bootstrap in for you automatically.

I have one extra using statement in my bootstrap for MvxLoaderPluginBootstrapAction. Here's the complete code:

using Cirrious.CrossCore.Plugins;
using Cirrious.MvvmCross.Community.Plugins.Sqlite;
using Cirrious.MvvmCross.Community.Plugins.Sqlite.Touch;
public class SqlitePluginBootstrap : MvxLoaderPluginBootstrapAction<PluginLoader, Plugin>
{
}