c# Unity container constructor injection of list<childs> -


i know how can inject list of child objects of abstract class constructor using xml config.

e.g.:

class test {  public test(list<a> instances) // list should have instance of b & c {  } }  abstract class {  }  class b: {  }  class c: {  } 

thanks!!!

you can use following config if change type of test's constructor argument on ilist<a>:

<configuration>   <configsections>     <section name="unity" type="microsoft.practices.unity.configuration.unityconfigurationsection, microsoft.practices.unity.configuration"/>   </configsections>   <unity xmlns="http://schemas.microsoft.com/practices/2010/unity">     <namespace name="system.collections.generic" />     <namespace name="consoleapplication1" />     <assembly name="consoleapplication1" />     <container>       <register type="a" mapto="b" name="b" />       <register type="a" mapto="c" name="c" />       <register type="ilist`1[[a]]" mapto="a[]" />     </container>   </unity> </configuration> 

so trick map ilist<a> interface on a[] - see this question details.


Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -