尝试:
-
我在VS2012中创建了一个新项目
-
我是通过NuGet包安装的RavenDB Embedded -Pre
-
我安装Ninject.MVC3
-
为ninject RavenDB添加了一个模块:
Public class RavenDBNinjectModule : NinjectModule
{
public override void Load()
{
Bind<IDocumentStore>().ToMethod(context =>
{
NonAdminHttp.EnsureCanListenToWhenInNonAdminContext(8080);
var documentStore = new EmbeddableDocumentStore { Url="http://localhost:8080/", DataDirectory="~/App_Data", UseEmbeddedHttpServer = true };
return documentStore.Initialize();
}).InSingletonScope();
Bind<IDocumentSession>().ToMethod(context => context.Kernel.Get<IDocumentStore>().OpenSession()).InRequestScope();
}
}
- 在我班“NinjectWebCommon”中......
private static void RegisterServices(IKernel kernel)
{
kernel.Load(new RavenDBNinjectModule());
}
运行应用程序时,生成了以下URL(“http://localhost:1423”)
Verify that the file "Raven.Studio.xap" was the root of my application
我尝试访问“http://localhost:8080”,但会显示以下屏幕:
我究竟做错了什么?
3 回答
您正在设置Url属性,这意味着您没有在嵌入模式下运行,而是在服务器模式下运行 . 删除Url属性,一切都适合您 .
我发现了问题!
因为他很快就使用了
IDocumentSession
,所以ninject没有创建IDocumentStore
的实例,因此没有运行Initialize
方法事实证明,问题是
documentStore.Initialize
永远不会被调用,因为没有人确实要求Ninject解决IDocumentStore
.