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

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -