绑定到单个 class 的多个接口
Multiple interfaces binded to a single class
我有这3个接口:
interface IA {}
interface IB {}
interface IC {}
此外,我还有另一个接口,它继承自 IA
、IB
和 IC
:
interface II : IA, IB, IC {}
然后,我还创建了一个 class CC
继承自 II
:
class CC : II {}
我已经创建了这些绑定:
this.Bind<IA>().To<CC>().InSingletonScope();
this.Bind<IB>().To<CC>().InSingletonScope();
this.Bind<IC>().To<CC>().InSingletonScope();
this.Bind<II>().To<CC>().InSingletonScope();
我不知道,每次我必须请求任何接口时,NInject 内核是否会提供相同的 CC
.
单例实例
所以,我的意思是:
IA ia = kernel.Get<IA>();
IB ib = kernel.Get<IB>();
ia
与 ib
?
是同一个实例
我怎么会出现这种行为?
据我所知,这应该可行:
this.Bind<IA, IB, IC, II>().To<CC>().InSingletonScope();
Bind
的重载最多需要四个类型参数。
我有这3个接口:
interface IA {}
interface IB {}
interface IC {}
此外,我还有另一个接口,它继承自 IA
、IB
和 IC
:
interface II : IA, IB, IC {}
然后,我还创建了一个 class CC
继承自 II
:
class CC : II {}
我已经创建了这些绑定:
this.Bind<IA>().To<CC>().InSingletonScope();
this.Bind<IB>().To<CC>().InSingletonScope();
this.Bind<IC>().To<CC>().InSingletonScope();
this.Bind<II>().To<CC>().InSingletonScope();
我不知道,每次我必须请求任何接口时,NInject 内核是否会提供相同的 CC
.
所以,我的意思是:
IA ia = kernel.Get<IA>();
IB ib = kernel.Get<IB>();
ia
与 ib
?
我怎么会出现这种行为?
据我所知,这应该可行:
this.Bind<IA, IB, IC, II>().To<CC>().InSingletonScope();
Bind
的重载最多需要四个类型参数。