我有一个 Web 项目,我希望它与 ravendb 和 ravendb-embedded 一起工作。所以这就是我认为我应该解决的方法。
两个项目,MvcRavendb 和 MvcRavendb-Embedded,这两个项目引用了两个不同的 nuget 包,一个用于 ravendb,一个用于 ravendb embedded。
在我的核心项目中,我有一个接口(interface) IDocumentStoreInitializer,它有一个方法,IDocumentStore InitializeDocumentStore()
MvcRavenDb 和 MvcRavenDb-Embedded 有一个这样的类
public class RegisterRavenDb : IDocumentStoreInitializer {
public IDocumentStore InitializeDocumentStore() {
return new DocumentStore OR EmbeddableDocumentStore();
}
}
然后我有一个类,像这样注册具体实现
public class RavenRegistry : Registry {
public RavenRegistry() {
For<IDocumentStoreInitializer>().Use<RegisterRavenDb>();
}
}
到目前为止一切顺利,但后来我有了像这样配置结构图的 Bootstrap
public class Bootstrapper {
public static IContainer Initialize() {
ObjectFactory.Initialize(x =>
{
// here I want to use the registered concrete implmentaiton of IDocumentStore
var documentStore = new DocumentStore { ConnectionStringName = "RavenDB" };
documentStore.Initialize();
}
}
}
那么我如何告诉 structuremap 使用 RavenRegistry 类中的 InitializeDocumentStore?也许我错过了什么或者我在这里采取了错误的方法
只需使用 EmbeddableDocumentStore 实例,使用连接字符串,您就可以控制将要嵌入的任何内容或服务器/客户端。
我是一名优秀的程序员,十分优秀!