Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wpf 如何在MVVMCross中覆盖插件注册_Wpf_Sqlite_Mvvmcross - Fatal编程技术网

Wpf 如何在MVVMCross中覆盖插件注册

Wpf 如何在MVVMCross中覆盖插件注册,wpf,sqlite,mvvmcross,Wpf,Sqlite,Mvvmcross,我在MVVMCross中使用WPF Sqlite插件,但我希望覆盖数据库写入的目录。我已经编写了一个自定义的ISQLiteConnectionFactory,它当前驻留在我的WPF引导程序项目中: internal class CustomMvxWpfSqLiteConnectionFactory : ISQLiteConnectionFactory { const string DirectoryName = "ProductName"; public ISQLiteConn

我在MVVMCross中使用WPF Sqlite插件,但我希望覆盖数据库写入的目录。我已经编写了一个自定义的
ISQLiteConnectionFactory
,它当前驻留在我的WPF引导程序项目中:

internal class CustomMvxWpfSqLiteConnectionFactory : ISQLiteConnectionFactory
{
    const string DirectoryName = "ProductName";

    public ISQLiteConnection Create(string address)
    {
        var appData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
        var dir = Path.Combine(appData, DirectoryName);
        Directory.CreateDirectory(dir);

        var path = Path.Combine(dir, address);
        return new SQLiteConnection(path, SQLiteOpenFlags.ReadWrite | SQLiteOpenFlags.Create, false);
    }
}
我搞不懂的是如何覆盖
Mvx.RegisterSingleton(新的MvxWpfSqLiteConnectionFactory())
cirrial.MvvmCross.Plugins.Sqlite.Wpf.Plugin

我的PCL项目的
App
注册了一个在初始化期间依赖于
ISQLiteConnectionFactory
的单例服务,因此我显然想在初始化之前覆盖IOC注册。但无论我做什么,插件注册的
MvxWpfSqLiteConnectionFactory
似乎优先于我自己注册的
CustomMvxWpfSqLiteConnectionFactory


我已经尝试在WPF Setup.cs中加入各种覆盖,但是到目前为止没有任何效果

中包含了一篇关于如何加载插件的文章

默认情况下,Sqlite插件是在设置中的
performbootstrapacations
期间初始化的-请参阅在启动序列中的位置

从您的问题来看,不清楚您在设置中尝试了哪些覆盖-我不确定“各种”包括哪些位置。但是,听起来像是想在
PerformBootstrapActions
之后和
InitializeApp
之前的任何时间点注册您的
ISQLiteConnectionFactory
——因此一种方法是覆盖
InitializeApp

protected virtual void InitializeApp(IMvxPluginManager pluginManager)
{
    // your code here
     base.InitializeApp(pluginManager);
}
可考虑的其他一些可能的想法:

  • 如果您想防止Sqlite插件在Wpf情况下自初始化,那么您可以从Wpf项目中删除Sqlite引导文件(但请注意,nuget可能会在以后再次尝试添加它)
  • MvvmCross sqlite项目的新“community fork”已将源代码更新为最新的sqlite net版本(通过@jarroda),并具有允许指定文件夹的
    BasePath
    CreateEx
    选项-请参阅