title: How to use Property Injection with AutoFac?
body: <p>In a Console application, I'm using Log4Net and in the Main method I'm getting the logger object. Now, I'd like to make this log object available in all my classes by letting all the classes inherit from a BaseClass which has a ILog property and is supposed to be set by Property Injection rather than Constructor Injection.</p>
  
  <p>I'm using AutoFac IoC container, how to inject my log Object to the Log property of my every class?</p>
  
  <p>What's the best/easiest way to achieve this?</p>
  
  <p>Is there any way to automatically resolve types?</p>
  
  <p>Below is my test application:</p>
  
  <pre><code>namespace ConsoleApplication1
  {
      class Program
      {
          static ILog Log;
          static IContainer Container;
  
          static void Main(string[] args)
          {                
             InitializeLogger();
  
             InitializeAutoFac();
  
              // the below works but could it be done automatically (without specifying the name of each class)?
             Product.Log = Container.Resolve&lt;ILog&gt;();
  
             // tried below but didn't inject ILog object into the Product
             Container.Resolve&lt;Product&gt;();
  
             RunTest();
  
              Console.ReadLine();
          }
  
          private static void RunTest()
          {
              var product = new Product();
              product.Do();
          }
  
          private static void InitializeAutoFac()
          {
              var builder = new ContainerBuilder();
  
              builder.Register(c =&gt; Log).As&lt;ILog&gt;();
  
              builder.RegisterType&lt;Product&gt;().PropertiesAutowired();
  
              Container = builder.Build();            
          }
  
          private static void InitializeLogger()
          {
              log4net.Config.XmlConfigurator.Configure();
  
              Log = LogManager.GetLogger("LoggerName");
          }
      }
  
      public class Product
      {
          public static ILog Log { get; set; }
  
          public void Do()
          {
              // this throws exception because Log is not set   
              Log.Debug("some Debug");  
          }
      }
  }
  </code></pre>