3
正如標題所說命名實例,structuremap不返回時,我還配置命名實例默認實例。structuremap不會返回,而不是默認的一個
這是我喜歡的類型註冊地:
/// <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實例被返回。 我在這裏做錯了什麼?