Note that there are some explanatory texts on larger screens.

plurals
  1. POUnity BuildUp without DependencyAttribute
    primarykey
    data
    text
    <p>I've got a third party library returning a class instace. It's out of my cotrol but I want to use <code>Unity</code> to inyect in its public properties. As I can not add <code>DependecyAttribute</code> to its properties because the class is not partial nor inheritalbe, I wondering if I can use <code>Unity</code> XML configuration to do the inyection.</p> <p>Is it possible to use <code>Unity's</code> XML configuration to configure build up dependencies? If answer is yes. How to configure XML to do it?</p> <p>I've tried:</p> <pre><code>&lt;register type="IService" mapTo="Service"&gt; &lt;!--Service has public constructor--&gt; &lt;/register&gt; &lt;!--ThirdPartyObj has no interface and no public constructor--&gt; &lt;register type="ThirdPartyObj " mapTo="ThirdPartyObj"&gt; &lt;!-- Inject the property "Service" --&gt; &lt;property name="Service" /&gt; //type of the property is IService &lt;/register&gt; </code></pre> <p>This config will work if <code>Unity Resolve</code> <code>ThidPartyObj</code> buy not working in <code>BuilUp</code> (Null reference in Service property) and can not <code>Resolve</code> <code>ThirdPartyObj</code> because has no public constructor.</p> <p>Simple example of what I want to archieve:</p> <pre><code>IUnityContainer uc = New UnityContainer() //create container container.LoadConfiguration() // load from XML config ThirdPartyObj foo = ThirdPartyLibrary.getFooInstace() //get third party instance container.BuildUp(foo.getType, foo) //inyect dependencies Console.WriteLine(foo.Service.getServiceMessage) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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