structuremap does return named instance instead of default one -
as title says, structuremap not return default instance when have configured named instances.
here type registration:
/// <summary> /// initializes new instance of <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); }
and how request instance:
_commandprocessor = _container.getinstance<icommandprocessor>(); // _container structuremap icontainer instance
i above line returns me commandcoordinator instance instead takenextcommandswitch instance returned. doing wrong here?
you need use add instead of use named instances:
for<icommandprocessor>().singleton().add<telephonycommandswitch>().named(typeof(telephonycommandswitch).fullname);
Comments
Post a Comment