使用 Ninject 绑定 Nhibernate.Burrow 的 ISession
我正在尝试使用 NHibenate、Burrow 和 Ninject。
我似乎无法使用 ninject 绑定 Burrow ISession。
我目前
Bind<ISession>().ToProvider( new BurrowFramework().GetSession()).InRequestScope();
遇到错误
cannot convert from 'NHibernate.ISession' to 'System.Type'
The best overloaded method match for 'Ninject.Syntax.IBindingToSyntax<NHibernate.ISession>.ToProvider(System.Type)' has some invalid arguments
我哪里错了?
I am trying use NHibenate, Burrow and Ninject.
I cannot seem to be able to bind the Burrow ISession using ninject.
I currently have
Bind<ISession>().ToProvider( new BurrowFramework().GetSession()).InRequestScope();
I get the errors
cannot convert from 'NHibernate.ISession' to 'System.Type'
The best overloaded method match for 'Ninject.Syntax.IBindingToSyntax<NHibernate.ISession>.ToProvider(System.Type)' has some invalid arguments
Where Am I going Wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
谢谢鲁本
你能帮我澄清一下吗
之间有什么区别
和
或
我本来期望第一个看起来像
,但它似乎有效,而这不起作用
Thanks Ruben
Would you clarify something for me
what is the difference between
and
or
I would have expected the first one to look like
but it appears to work while this does not
您可能想做:
查看 Ninject 文档 - ToProvider 指的是 Ninject 提供程序要求的特定接口,它允许您干净地管理更复杂的工厂(而不是像上面那样几乎像内联工厂方法一样工作的东西) )。
编辑:我将您的评论解释为暗示您尝试过,但发现我在假设 ToMethod 重载的情况下搞砸了,其中委托没有参数,委托语法中的细微差别让您感到困惑。如果不是这样,我应该写:
现在,C# 语法的快速总结:
在 C# 2 中,我们有如下匿名委托:
在 C# 3 中,我们可以按如下方式创建 lambda:
匹配任何类型的 0、1, 1 个 X 类型,2 个任何类型,一个 X 后跟一个 Y 分别
它们都是等价的 - 编译器为每个类型生成相同的输出。
不同之处在于 lambda 语法中没有与语法 0 等效的语法。
强烈推荐 Jon Skeet 的《C# in Depth》,它让所有这些内容变得清晰(但请等待几个月后的第二版)
(如果有时间给出更深入的答案,请查看 Ninject 源代码/API,看看是否它们在始终或从不传递上下文方面是一致的)
You probably want to do:
Have a look at the Ninject docs - ToProvider refers to a specific interface that a Ninject provider mandates, which allows you to manage more complex factories cleanly (as opposed to stuff that works nearly as an inline factory method as above).
EDIT: I interpret your comment as implying that you tried it but discovered I'd messed up in assuming that there was an overload of ToMethod where the delegate has no parameters, which subtle differences in delegate syntax are confusing you with. If that's not the case, I should have written:
Now, quick summary of C# syntax:
In C# 2, we had anonymous delegates as follows:
In C# 3, we can create lambdas as follows:
Which match zero, 1 of any type, 1 of type X, 2 of any type, an X followed by a Y respectively
They are all equivalent - the compiler generates the same output for each.
The difference is that there is no equivalent of syntax 0 in lambda syntax.
Highly recommend Jon Skeet's C# in Depth for making all this stuff clear (but wait for the second edition which is a short number of months away)
(If had time to give more in depth answer would look at the Ninject sources/APIs and see if they are consistent in always or never passing a context)