Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Based on your posted code, there shouldn't be a problem.</p> <p>I created 2 projects: a console application and a class library called ThirdPartyLibrary.</p> <p>The ThirdPartyLibrary consists of the following (extrapolated from the posted code):</p> <pre><code>namespace ThirdPartyLibrary { public interface IService { string GetServiceMessage { get; } } public class Service : IService { public Service() { } public string GetServiceMessage { get { return "The message!"; } } } public static class ThirdPartyLibrary { public static ThirdPartyObj GetFooInstance() { return new ThirdPartyObj(); } } public interface IThirdPartyObj { } public class ThirdPartyObj : IThirdPartyObj { internal ThirdPartyObj() { } public IService Service { get; set; } } } </code></pre> <p>The XML Configuration looks like this:</p> <pre><code>&lt;?xml version="1.0"?&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;container&gt; &lt;register type="ThirdPartyLibrary.IService, ThirdPartyLibrary" mapTo="ThirdPartyLibrary.Service, ThirdPartyLibrary"&gt; &lt;/register&gt; &lt;register type="ThirdPartyLibrary.IThirdPartyObj, ThirdPartyLibrary" mapTo="ThirdPartyLibrary.ThirdPartyObj, ThirdPartyLibrary"&gt; &lt;!-- Inject the property "Service" --&gt; &lt;property name="Service" /&gt; &lt;/register&gt; &lt;/container&gt; &lt;/unity&gt; &lt;startup&gt; &lt;supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/&gt; &lt;/startup&gt; &lt;/configuration&gt; </code></pre> <p>And the console application is:</p> <pre><code>class Program { static void Main(string[] args) { IUnityContainer container = new UnityContainer(); //create container container.LoadConfiguration(); // load from XML config ThirdPartyObj foo = ThirdPartyLibrary.ThirdPartyLibrary.GetFooInstance(); //get third party instance container.BuildUp(foo.GetType(), foo); //inyect dependencies Console.WriteLine(foo.Service.GetServiceMessage); } } </code></pre> <p>This works fine and outputs <code>The message!</code> as expected. Perhaps, the exact scenario is not the same as your posted (I assume fictitious) example or something else is not configured properly? </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