我在 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<ISQLiteConnectionFactory>(new MvxWpfSqLiteConnectionFactory());它Cirrious.MvvmCross.Plugins.Sqlite.Wpf.Plugin。
我的 PCL 项目App注册了一个在初始化期间依赖的单例服务ISQLiteConnectionFactory,所以我显然想在那之前覆盖 IOC 注册。但无论我做什么,插件的注册MvxWpfSqLiteConnectionFactory而不是我自己的注册CustomMvxWpfSqLiteConnectionFactory似乎优先。
我已经尝试将我的注册调用放在我的 WPF Setup.cs 中的各种覆盖中,但到目前为止没有任何效果。