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