Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我希望我的应用程序始终将服务用作单例,如何将 Ninject 设置为默认使用单例范围。我使用约定来注册我的类型,我需要使用 Bind<> 方法吗?
Hy,假设您的所有服务都从您那里继承,IService可以编写以下内容
IService
添加以下 using 语句
using Ninject.Extensions.Conventions;
使用约定,如
kernel.Bind( x => x .FromThisAssembly() .SelectAllClasses().InheritedFrom<IService>() .BindAllInterfaces() .Configure(b => b.InSingletonScope()));
您可能需要根据自己的需要稍微调整一下。
我是位运算的初学者(在 C 方面也不是很有经验),我遇到了以下表达式:
x |= (1<<y)
起初我以为它的意思是“x 等于 x 或 y 左移一位”,但后来我意识到这将是:
x |= (y<<1)