gpt4 book ai didi

c# - 在 StructureMap 中使用 Registry 创建可插拔架构

转载 作者:太空宇宙 更新时间:2023-11-03 14:12:25 25 4
gpt4 key购买 nike

我有一个 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 实例,使用连接字符串,您就可以控制将要嵌入的任何内容或服务器/客户端。

关于c# - 在 StructureMap 中使用 Registry 创建可插拔架构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7430106/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com