我们在项目中使用 Db4o。
我有一些自动测试,测试对象的持久性。问题是,我无法两次打开/创建数据库。我有两种获取对象容器的辅助方法。但是当第二次调用该方法时,“ArgumentException:配置已使用”。被抛出。我当然关闭并处理了以前的对象容器。
我做错了什么?
代码:
public static IObjectContainer GetEmptyTestingDatabase() {
var tempDir = Environment.GetFolderPath(Environment.SpecialFolder.InternetCache);
string dbFilePath = Path.Combine(tempDir, "UNIT-TESTING.db4o");
if (File.Exists(dbFilePath)) {
File.Delete(dbFilePath);
}
var cfg = Db4oFactory.Configure();
cfg.Add(new TransparentPersistenceSupport(new DeactivatingRollbackStrategy()));
cfg.Add(new TransparentActivationSupport());
var db = Db4oFactory.OpenFile(cfg, dbFilePath);
return db;
}
public static IObjectContainer GetMemoryDatabase() {
string dbFileName = Guid.NewGuid().ToString().ToString();
var cfg = Db4oFactory.Configure();
cfg.Storage = new Db4objects.Db4o.IO.PagingMemoryStorage();
cfg.Add(new TransparentPersistenceSupport(new DeactivatingRollbackStrategy()));
cfg.Add(new TransparentActivationSupport());
var db = Db4oFactory.OpenFile(cfg, dbFileName);
return db;
}