Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I think you need to specify which type is the generic using when declaring the alias. I've done a sample for <a href="https://stackoverflow.com/questions/3996267/how-to-inject-a-generic-ilist-of-objects-using-unity-2-xml-config/4120032#4120032">How to inject a generic IList&lt;&gt; of objects using Unity 2 XML config?</a> like the following.</p> <p>List Suppose you want to use resolve from "IList" to "List". </p> <p><strong>1</strong> First you will have to prepare your configuration file, in this case it's using signed references to IList as well as List.</p> <pre><code> &lt;?xml version="1.0" encoding="utf-8" ?&gt; &lt;configuration&gt; &lt;configSections&gt; &lt;section name="unity" type="Microsoft.Practices.Unity.Configuration.UnityConfigurationSection, Microsoft.Practices.Unity.Configuration"/&gt; &lt;/configSections&gt; &lt;unity xmlns="http://schemas.microsoft.com/practices/2010/unity"&gt; &lt;alias alias="StringListContract" type="System.Collections.Generic.IList`1[[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /&gt; &lt;alias alias="ConcreteStringList" type="System.Collections.Generic.List`1[[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /&gt; &lt;container&gt; &lt;register type="StringListContract" mapTo="ConcreteStringList"&gt; &lt;lifetime type="ContainerControlledLifetimeManager" /&gt; &lt;constructor /&gt; &lt;/register&gt; &lt;/container&gt; &lt;/unity&gt; &lt;/configuration&gt; </code></pre> <p><strong>2</strong> Use the container to resolve the dependency ;-)</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.Practices.Unity; using Microsoft.Practices.Unity.Configuration; namespace UnityTerminal { class Program { static void Main(string[] args) { var container = new UnityContainer(); container.LoadConfiguration(); { var concreteStringList = container.Resolve&lt;System.Collections.Generic.IList&lt;System.String&gt;&gt;(); concreteStringList.Add("Hello World"); } { var concreteStringList = container.Resolve&lt;System.Collections.Generic.IList&lt;System.String&gt;&gt;(); Console.WriteLine("{0}", concreteStringList[0]); } Console.ReadKey(); } } } </code></pre> <p>That should be enough, I hope this works ;-) Best regards, Herber</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload