【发布时间】:2013-05-30 14:18:49
【问题描述】:
我想出了一个可行的解决方案,将 RavenDB 中的多个数据库用于使用 Castle Windsor 进行布线的 ASP.Net MVC 应用程序。
这是当前的安装程序
public class RavenInstaller : IWindsorInstaller
{
public void Install(IWindsorContainer container, IConfigurationStore store)
{
container.Register(
Component.For<IDocumentStore>().Instance(CreateDocumentStore()).LifeStyle.Singleton,
Component.For<IDocumentSession>().UsingFactoryMethod(GetDocumentSesssion).LifeStyle.PerWebRequest
);
}
static IDocumentStore CreateDocumentStore()
{
var store = new DocumentStore { ConnectionStringName = "RavenDb_CS9" };
store.Initialize();
IndexCreation.CreateIndexes(typeof(Users).Assembly, store);
return store;
}
static IDocumentSession GetDocumentSesssion(IKernel kernel)
{
var store = kernel.Resolve<IDocumentStore>();
return store.OpenSession();
}
}
上述方法完美但仅适用于一个数据库。
我找不到如何处理另一个数据库的正确想法。整个链从请求IDocumentSession 的域服务开始。然后流程如上述安装程序中指定。但是我在哪里/如何要求“SessionToDb1”或“SessionToDb2”?
当然重要的是要使用什么连接字符串(指定了 DB 属性),还有要在各自的 DB/DocumentStore 中创建什么索引。
有人使用 Windsor 完成此任务吗?我在这里想/攻击错了吗?
谢谢!
【问题讨论】:
-
此链接可能对您有所帮助:stackoverflow.com/questions/3531552/…
-
谢谢!我目前正在研究配置选项 .Named() ,您可以在其中命名每个注册并在解析时使用它(而不是类型)。有希望。您的链接让我朝着正确的方向前进。
标签: asp.net-mvc castle-windsor ravendb ioc-container