Kernel 如何将第二个相同类型的实例绑定到内核,并在Ninject中区分它们?

Kernel 如何将第二个相同类型的实例绑定到内核,并在Ninject中区分它们?,kernel,ninject,bind,Kernel,Ninject,Bind,我正在使用White framework自动化Windows应用程序。应用程序是一类白色框架 在测试过程中,我通过getApplication()方法获取一个应用程序实例,将其绑定到内核,放入serviceLocator并将该实例保持为Singleton: IKernel kernel = new StandardKernel(); kernel.Bind<Application>().ToMethod(ctx => getApplication()).InSingletonS

我正在使用White framework自动化Windows应用程序。应用程序是一类白色框架

在测试过程中,我通过getApplication()方法获取一个应用程序实例,将其绑定到内核,放入serviceLocator并将该实例保持为Singleton:

IKernel kernel = new StandardKernel();
kernel.Bind<Application>().ToMethod(ctx => getApplication()).InSingletonScope();            
ServiceLocator.SetLocatorProvider(() => new NinjectServiceLocator(kernel));
IKernel内核=新的标准内核();
kernel.Bind().ToMethod(ctx=>getApplication()).InSingletonScope();
SetLocatorProvider(()=>新的NinjectServiceLocator(内核));
每当我需要获取应用程序时,我都会使用以下代码:

Application application = ServiceLocator.Current.GetInstance<Application>();
Application=ServiceLocator.Current.GetInstance();
到目前为止,它对我很管用

但经过几个步骤后,我需要获得另一个应用程序实例,它与第一个应用程序实例不同

如何使用ServiceLocator将第二个应用程序实例绑定到内核?以及如何使用服务定位器获取第二个实例(因为这两个实例具有相同的类型)


提前感谢您的帮助。

我是否应该使用“Name”方法,如:“kernel.Bind().ToMethod(ctx=>getApplication()).InSingletonScope().Name(“app1”);”当我需要它时,我会使用:Application application1=ServiceLocator.Current.GetInstance(“app1”);看起来上面的解决方案是有效的。。。