作者热门文章
- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
好吧,这个问题从标题就很简单了。
对于局部变量factory
:
var factory = Fluently.Configure()
...
这两行是否等价:
Bind<ISessionFactory>().ToConstant(factory).InSingletonScope();
和:
Bind<ISessionFactory>().ToConstant(factory);
最佳答案
在最新版本的 ninject 中,当您创建 ToConstant 绑定(bind)时,它会自动将 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;
}
关于c# - 绑定(bind) ToConstant 和调用 InSingletonScope 是多余的吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7395071/
我们有如下代码。 var xyz = method(); //method() returns an interface say **Interface1** kernel.Bind().ToCons
好吧,这个问题从标题就很简单了。 对于局部变量factory: var factory = Fluently.Configure() ... 这两行是否等价: Bind().ToConstant(fa
我想将 IServiceProvider 绑定(bind)到 Ninject IKernel 实现。有什么用处 Bind().ToConstant(this).InTransientScope();
我是一名优秀的程序员,十分优秀!