忍者+具有两个或多个数据库的 NHibernate
我已经在 NinjectModule 中声明了我的 Ninject 绑定,如下所示:
public override void Load()
{
Bind<ISessionFactory>().ToMethod(c => SessionFactory1.SessionFactory).InSingletonScope().Named("d1");
Bind<ISessionFactory>().ToMethod(c => SessionFactory2.SessionFactory).InSingletonScope().Named("d2");
Bind<ISession>().ToMethod(c => c.Kernel.Get<ISessionFactory>("d1").OpenSession()).Named("d1");
Bind<ISession>().ToMethod(c => c.Kernel.Get<ISessionFactory>("d2").OpenSession()).Named("d2");
Bind(typeof(IReadOnlyRepository<,>)).To(typeof(Repository<,>)).Named("d1").WithConstructorArgument("session", c => c.Kernel.Get<ISession>("d1"));
Bind(typeof(IReadOnlyRepository<,>)).To(typeof(Repository<,>)).Named("d2").WithConstructorArgument("session", c => c.Kernel.Get<ISession>("d2"));
}
如果运行 a 来解析 IReadonlyRepository,我会从 Ninject 中得到一个异常(ActivationException:激活 Repository{ulong,Workflow} 时出错),任何人都可以发现我的绑定配置中的错误吗?
IReadOnlyRepository repository1 = kernel.Get<Repository<UInt64, Workflow>>("d1");
I have declared my Ninject bindings in a NinjectModule like this:
public override void Load()
{
Bind<ISessionFactory>().ToMethod(c => SessionFactory1.SessionFactory).InSingletonScope().Named("d1");
Bind<ISessionFactory>().ToMethod(c => SessionFactory2.SessionFactory).InSingletonScope().Named("d2");
Bind<ISession>().ToMethod(c => c.Kernel.Get<ISessionFactory>("d1").OpenSession()).Named("d1");
Bind<ISession>().ToMethod(c => c.Kernel.Get<ISessionFactory>("d2").OpenSession()).Named("d2");
Bind(typeof(IReadOnlyRepository<,>)).To(typeof(Repository<,>)).Named("d1").WithConstructorArgument("session", c => c.Kernel.Get<ISession>("d1"));
Bind(typeof(IReadOnlyRepository<,>)).To(typeof(Repository<,>)).Named("d2").WithConstructorArgument("session", c => c.Kernel.Get<ISession>("d2"));
}
If a run a to resolved a IReadonlyRepository I get an exception from Ninject (ActivationException: Error activating Repository{ulong, Workflow}) can anyone spot the error in my binding configuration?
IReadOnlyRepository repository1 = kernel.Get<Repository<UInt64, Workflow>>("d1");
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

尝试使用不同的名称,如下所示:
Try with different name like these: