嗯,这个问题从标题就已经很简单地说明了。
对于局部变量factory
:
var factory = Fluently.Configure()
...
这两行是否等价:
Bind<ISessionFactory>().ToConstant(factory).InSingletonScope();
and:
Bind<ISessionFactory>().ToConstant(factory);
在最新版本的 ninject 中,当您创建 ToConstant 绑定时,它会自动将 Scope 设置为 Singleton。就这样InSingletonScope()
你的例子中的部分是多余的。来自 ninject 代码库:
/// <summary>
/// Indicates that the service should be bound to the specified constant value.
/// </summary>
/// <param name="value">The constant value.</param>
public IBindingWhenInNamedWithOrOnSyntax<T> ToConstant(T value)
{
Binding.ProviderCallback = ctx => new ConstantProvider<T>(value);
Binding.Target = BindingTarget.Constant;
Binding.ScopeCallback = StandardScopeCallbacks.Singleton;
return this;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)