正如标题所说,当我还配置了命名实例时,结构映射不会返回默认实例。
这是我的类型注册:
/// <summary>
/// Initializes a new instance of the <see cref="CommandProcessingTypeRegistry"/> class.
/// </summary>
public CommandProcessingTypeRegistry()
{
For<ICommandProcessor>().Singleton().Use<CommandCoordinator>();
For<ICommandProcessor>().Singleton().Use<SystemCommandSwitch>().Named(typeof(SystemCommandSwitch).FullName);
For<ICommandProcessor>().Singleton().Use<TelephonyCommandSwitch>().Named(typeof(TelephonyCommandSwitch).FullName);
For<ICommandProcessor>().Singleton().Use<AudioCommandSwitch>().Named(typeof(AudioCommandSwitch).FullName);
For<ICommandProcessor>().Singleton().Use<TetraCommandSwitch>().Named(typeof(TetraCommandSwitch).FullName);
For<ICommandProcessor>().Singleton().Use<RadioCommandSwitch>().Named(typeof(RadioCommandSwitch).FullName);
For<ICommandProcessor>().Singleton().Use<SnapshotCommandSwitch>().Named(typeof(SnapshotCommandSwitch).FullName);
For<ICommandProcessor>().Singleton().Use<TakeNextCommandSwitch>().Named(typeof(TakeNextCommandSwitch).FullName);
}
这就是我请求实例的方式:
_commandProcessor = _container.GetInstance<ICommandProcessor>(); // _container is the structuremap IContainer instance
我希望上面的行返回CommandCoordinator实例,而是返回TakeNextCommandSwitch实例。我在这里做错了什么?