title: Setter / property injection in Unity without attributes
body: <p>I am working on a project where the Unity framework is used as the IoC container. My question relates to injecting an optional dependency (in this case a logger) into several classes using property- or setter injection. </p>
  
  <p>I do not want to clutter the constructors of all my classes with these optional dependencies, but I cannot find a good way to handle this in Unity. The way you would do this is, according to the <a href="http://msdn.microsoft.com/en-us/library/cc440933.aspx" rel="noreferrer">MSDN documentation</a>, by adding an attribute to the property:</p>
  
  <pre><code>private ILogger logger; 
  
  [Dependency]
  public ILogger Logger
  {
  get { return logger; }
    set { logger = value; }
  }
  </code></pre>
  
  <p>I find this very ugly. In <a href="http://structuremap.sourceforge.net" rel="noreferrer">StructureMap</a> one could do the following to set all properties of a given type:</p>
  
  <pre><code>SetAllProperties(policy =&gt; policy.OfType&lt;ILog&gt;());
  </code></pre>
  
  <p>Does anyone know if it is possible to do something similar in Unity?</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>Kim Major suggests using <a href="http://aardvarkblogs.wordpress.com/unity-container-tutorials/10-setter-injection/" rel="noreferrer">this approach</a> which can also be achieved through code. </p>
  
  <p>I would be interested in examples of how to do this automatically for all matching properties.</p>