我正在使用以下代码注册组件:
StandardKernel kernel = new StandardKernel();
string currentDirectory = Path.GetDirectoryName(GetType().Assembly.Location)
foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
{
if (!Path.GetDirectoryName(assembly.Location).Equals(currentDirectory))
continue;
foreach (var type in assembly.GetTypes())
{
if (!type.IsComponent())
continue;
foreach (var @interface in type.GetInterfaces())
kernel.Bind(@interface).To(type).InSingletonScope();
}
}
我有一个类实现了两个接口:
class StandardConsole : IStartable, IConsumer<ConsoleCommand>
如果我解析IStartable
,我会得到一个实例,如果我解析IConsumer<ConsoleCommand>
,我会得到另一个实例。
如何获取这两个接口的相同实例?